我需要创建一个位于服务器(托管在IIS中)的WCF服务,并侦听任何HTTP GET请求在某个URL处击中服务器。用于处理HTTP GET请求的WCF服务
更具体地说,当一个有效的GET请求到达服务器时,Id想要检查在URL中编码的参数。
下面是我的界面代码:
[ServiceContract]
public interface IHttpHandler
{
[OperationContract(Action = "*", ReplyAction = "*")]
void HandleMessage(Message m);
[OperationContract]
[WebInvoke(UriTemplate = "HandleEchoRequest", Method = "GET")]
string HandleEchoRequest(Stream request);
}
执行代码(svc.cs文件):
public void HandleMessage(Message m)
{
//do some work
}
public string HandleEchoRequest(Stream request)
{
//...do something here
return "asdf";
}
我能成功击中SVC:
http://localhost/HttpMessageProcessor/HttpHandler.svc
然而,当我连接到W3WP流程时,我似乎无法进入转折点集。最终Id喜欢使用HTTPS。
在WCF服务项目我的web.config文件:
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
的App.config在客户端:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHttpHandler" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/HttpMessageProcessor/HttpHandler.svc"
behaviorConfiguration="webBehavior" binding="webHttpBinding"
contract="Proxy.IHttpHandler" name="BasicHttpBinding_IHttpHandler" />
</client>
</system.serviceModel>
客户端代码:
using (var service = new Proxy.HttpHandlerClient())
{
}
Console.ReadKey();
我想两件事情看看我是否可以进入代码: 1.点击CTRL + F5在控制台项目上启动客户端,然后查看我是否可以附加到W3WP进程。 2.运行在调试模式下的客户端,看看我能指向一个URL,例如:
http://localhost/HttpMessageProcessor/HttpHandler.svc/HandleEchoRequest/
上述方法都不似乎工作。
我已经看过网络的建议,并尝试了一些事情,我已经休息了我在这里提到的代码。任何建议/想法的欢迎!
编辑 我遇到了this网站,并实现了一个简单的解决方案如下。 我能成功击中断点的handleMessage执行设定当我在浏览器中输入以下网址:
代码:
[ServiceContract]
public interface IService1
{
[OperationContract(Action = "*", ReplyAction = "*")]
void HandleMessage(Message m);
}
public class Service1 : IService1
{
public void HandleMessage(Message m)
{
//do something here.
}
}
App.config中的服务:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我的客户代码:
Uri baseAddress = new Uri("http://localhost/TestWCFSite/TestWCFService.svc/");
Uri endpointAddress = new Uri("http://localhost/TestWCFSite/TestWCFService.svc/HandleMessage/");
var binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.None, Encoding.UTF8), new HttpTransportBindingElement());
ServiceHost service = new ServiceHost(typeof(Service1), baseAddress);
service.AddServiceEndpoint(typeof(IService1), binding, endpointAddress);
service.Open();
var message = string.Format("Service open at {0} - press a key to continue", baseAddress);
Console.WriteLine(message);
Console.ReadKey();
service.Close();
我的问题是现在试图在IIS中承载它并让它处理断点命中。
嘿,你好 - 使用Visual Studio。我在同一个解决方案中获得了客户端和WCF服务。当我附上时,它表示客户端代码不会被纳入..合理。 WCF代码是鲜红的,这意味着它应该打... – TheRenoRanger