Wcf 3.5 - 具有不同绑定和SOAP的不同端点

问题描述:

我有一个问题...我探索了整个互联网,我不知道我在做什么错。Wcf 3.5 - 具有不同绑定和SOAP的不同端点

问题:WCF的Web服务,.NET Framework 3.5的,2个不同类型的客户机(手持设备及一般计算机)

我想要做的是创造2个diferent端点,一个与basicBinding(对于SOAP请求)和其他与wsBinding(通常为计算机)

所以我走通的web.config和我创建2个不同的绑定,拥有两个不同的端点相关:

<bindings> 
    <basicHttpBinding> 
    <binding name="BasicBinding" openTimeout="00:10:00" receiveTimeout="23:59:00" 
     sendTimeout="23:59:00" messageEncoding="Text" /> 
    </basicHttpBinding> 
    <wsHttpBinding> 
    <binding name="DefaultBinding" openTimeout="00:10:00" receiveTimeout="23:59:59" 
     sendTimeout="23:59:59"> 
     <reliableSession inactivityTimeout="01:00:00" /> 
     <security mode="None"> 
     <transport clientCredentialType="None" /> 
     <message clientCredentialType="None" /> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<services> 
    <service behaviorConfiguration="qtswsdl.QTS_ServiceBehavior" 
    name="qtswsdl.QTS_Service"> 
    <endpoint address="http://host.com/service.svc/ForHh" 
     binding="basicHttpBinding" bindingConfiguration="BasicBinding" 
     name="handHeldEndPoint" contract="qtswsdl.QTSPort" /> 
    <endpoint address="http://host.com/service.svc/ForCp" 
     binding="wsHttpBinding" bindingConfiguration="DefaultBinding" 
     name="coProcessorEndPoint" contract="qtswsdl.QTSPort" /> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="qtswsdl.QTS_ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
     <serviceDebug includeExceptionDetailInFaults="true" /> 
     <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     <serviceThrottling maxConcurrentCalls="2147483647"maxConcurrentSessions="2147483647" 
     maxConcurrentInstances="2147483647" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

因此,当我尝试发送SOAP消息到“http://host.com/service.svc/ForHh”我得到一个“HTTP 400 - 错误的请求”(/ ForCp也不工作)

我尝试与自定义客户端,与WcfTestClient.exe和我无法鳍发生了什么

任何提示或建议?

感谢您的时间

编辑:

使SVC跟踪后,我得到了一些例外:

<Message>The message with Action 'http://Host.com/Service.svc/ForHh' 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).</Message> 

有趣的是,我在编程发送SOAP请求。这是我的理解,如果我以编程方式发送SOAP请求,我不需要定义任何合同,因为它默认使用SOAP 1.1进行发送。发送请求

代码如下代码:

private string SendRequestAndGetAnswerFromWebService(string methodName, string requestXml){ 

    StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""); 
       soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "); 
       soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"); 
       soapRequest.Append(requestXml);//Body 
       soapRequest.Append("</soap:Body></soap:Envelope>"); 

        WebRequest webRequest = WebRequest.Create(@"http://Host.com/Service.svc/" + methodName); 
        HttpWebRequest httpRequest = (HttpWebRequest)webRequest; 
        httpRequest.Method = "POST"; 
        httpRequest.ContentType = "text/xml; charset=ascii"; 
        httpRequest.Headers.Add("SOAPAction: " + @"http://Host.com/Service.svc/Service.svc/" + methodName); 
        httpRequest.ProtocolVersion = HttpVersion.Version11; 
        httpRequest.Credentials = CredentialCache.DefaultCredentials; 
        httpRequest.Timeout = 7000; 
        httpRequest.ContentLength = System.Text.Encoding.ASCII.GetByteCount(soapRequest.ToString()); 
        Stream requestStream = httpRequest.GetRequestStream(); 

        //Create Stream and send Request 
        StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII); 
        streamWriter.Write(soapRequest.ToString()); 
        //Send the request    
        streamWriter.Close(); 

        //Get the Response 
        HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse(); 
        StreamReader srd = new StreamReader(wr.GetResponseStream()); 
        string resulXmlFromWebService = srd.ReadToEnd(); 
        return resulXmlFromWebService; 
} 

也许我对编程发送是错误的合同和SOAP消息的假设......

+0

打开wcf跟踪并得到确切的错误:http://blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx – 2012-04-24 18:02:20

+0

编辑。谢谢你的时间球员 – JTH 2012-04-25 07:34:46

+0

肥皂头似乎是错误的。你可以在wsdl中看到正确的一个。 – 2012-04-25 10:15:23

一般情况下,这是非常不好的做法 - 你不应该以这种方式手动创建对WCF服务的SOAP请求。如果您要利用开箱即用的WCF请求/回复范例而不是手动设置标题,那更好。

我会推荐的是创建一个替代的例子,您可以实现同样的开箱即用(可能DataContracts,OperationContracts和ServiceContracts在客户端,也许利用WebHttpBehavior和WebHttpBinding )。检查在该场景中发送和接收的确切消息,并逐字逐个仔细检查这些消息与您在此处发送的消息的不同。

另外,很难说只要你提供的细节你可能做错了什么。

这里是我的建议:

一般来说,一旦你这样做,你应该有更多关于服务端会发生什么变化的信息,并且可以很快诊断问题。试试吧,请回报! :)

+0

感谢您的建议。让我们试试 – JTH 2012-04-28 11:21:34

+0

抱歉,延迟。你的建议让我注意到了真正的问题。肥皂消息没有需要的值。 – JTH 2012-05-27 10:34:13