开发者

wcf service Internal server error

开发者 https://www.devze.com 2023-03-26 20:56 出处:网络
I created a simple wcf service that exposes a GetData method. It\'s actually the template created when you create a new wcf project.

I created a simple wcf service that exposes a GetData method. It's actually the template created when you create a new wcf project.

I added the application to iis server, so it can be accessed from the outside, like this: http://192.168.0.100/TFSWrapper/Service1.svc

I used a generic soap client to send a request to the GetData method. This is the soap request that was generated:

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:so开发者_运维百科ap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetData xmlns="http://tempuri.org/" />
  </soap:Body>
</soap:Envelope>

Here is the soap response:

<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <GetDataResponse xmlns="http://tempuri.org/">
      <GetDataResult>You entered: 87</GetDataResult>
    </GetDataResponse>
  </s:Body>
</s:Envelope>

By the way, I removed the parameter from the method and hardcoded a return value.

As you can see, everything works as it should.

Next, I created a Titanium client that calls the same service. I used the exact soap request as above, just to make sure.

Basically I did this:

var s='<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetData xmlns="http://tempuri.org/" /></soap:Body></soap:Envelope>';
        //xhr.send(config.envelopeBegin+body+config.envelopeEnd);
        xhr.send(s);

When this is sent, the server is returning a "500 internal server error" response together with the following fault string:

The message with Action 'http://tempuri.org/GetData' 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).

At first I used the titanium soap api to create the request xml, but I was getting the same error. I though it was a problem with how that is created, so that's why I hard-coded a request (that works), but still no luck.


By default, WCF Service OperationContracts can only be invoked using an HTTP POST. When you call open() on the Titanium HTTPClient, are you specifying a GET or POST for HTTP method parameter?

Secondly, since your service binding is using SOAP 1.1, you need to pass a SOAPAction header in your request so that WCF can route the message to the GetData method. If an Action parameter is not specified in the service's OperationContract attribute, the Action should be the method name preceded by the namespace and service contract name (probably http://tempuri.org/IService1/GetData if you're using what the default WCF application created). You'll also need to specify a content-type. So, you'd need to setup your xhr like this prior to calling send:

xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-16');
xhr.setRequestHeader('SOAPAction', '"http://tempuri.org/IService1/GetData"');
xhr.send(s);

Also, you can explicitly specify an action for a WCF service operation:

[OperationContract(Action = "MyAction")]
string GetData()
{
    // ...snip...
}

xhr.setRequestHeader('SOAPAction', '"MyAction"');

And lastly, you can allow service operations to be invoked via an HTTP GET by decorating the method with the [WebGet] attribute. This allows the operation to be called in REST fashion: http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消