【问题标题】:How do I get to explore WCF methods with a browser?如何使用浏览器探索 WCF 方法?
【发布时间】:2013-01-01 14:24:31
【问题描述】:

我有一个 net.tcp 服务,我想让其他平台(特别是 PHP)可以访问它。为此,我使用的是 http 绑定。

我正在创建一个 http 端点:

ServiceHost svh = new ServiceHost(typeof(MyService));
var httpLocation = "http://" + address + ":4041";
svh.AddServiceEndpoint(typeof(IMyService), new WebHttpBinding(WebHttpSecurityMode.None), 
                                   httpLocation);

svh.AddServiceEndpoint(
                    ServiceMetadataBehavior.MexContractName,
                    MetadataExchangeBindings.CreateMexHttpBinding(),
                    httpLocation + "/mex"
                    );

svh.Open();

现在,当我尝试通过浏览器访问 http://localhost:4041 来探索服务时,我得到:

<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none">
<Code>
<Value>Sender</Value>
<Subcode>
<Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</Value>
</Subcode>
</Code>
<Reason>
<Text xml:lang="en-US">
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
</Text>
</Reason>

我做错了什么?

【问题讨论】:

  • 您尝试浏览的 URL 是什么(或其示例)?
  • 您如何托管您的 WCF?是通过 Visual Studio 还是 IIS?

标签: c# .net wcf webhttpbinding


【解决方案1】:

浏览时,请确保包含.svc.asmx 的完整路径以及尾部?wsdl

localhost:4041/ServiceVirtualDirectory/Service.svc?wsdl

【讨论】:

  • 在我的情况下,这条路是什么?我试过访问http://localhost:4041/Service.svc?wsdl 没有任何成功。我不太确定 Service.svc 是什么以及我应该从哪里获取它
  • 很难说,你是在IIS中托管的吗?通常第一个斜杠是虚拟目录的名称,第二个是 WCF 项目的名称。
【解决方案2】:

您是否尝试过访问http://localhost:4041/MyService.svc?wsdl

不确定您的服务在设计上是否符合 REST,这就是您使用 WebHttpBinding 的原因。 如果您的服务实际上是 REST-ful,则其格式为 http://localhost:4041/MyService.svc/MyMethod/MyData 你应该在浏览器上看到结果。基于this ASP.NET 线程,您需要附加一个WebHttpBehavior

如果您的服务不是 REST-ful,则应根据您的要求考虑BasicHttpBinding(使用常规 SOAP 消息)或其近亲(请参阅this SO 线程)。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多