0

我有一个 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>

我究竟做错了什么?

4

2 回答 2

1

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

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

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

希望这可以帮助。

于 2013-01-18T06:11:33.623 回答
1

When browsing, make sure to include the full path to the .svc or .asmx along with a trailing ?wsdl.

localhost:4041/ServiceVirtualDirectory/Service.svc?wsdl
于 2013-01-17T22:43:35.430 回答