我正在从我的 iphone 应用程序中请求 WCF 方法。但我总是得到一个 falutString 作为回应。
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<soapenv:Envelope \n"
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" \n"
"xmlns:tem=\"http://tempuri.org/\" \n"
"xmlns=\"http://WssMobileService.Model/2012/ServiceContractDslModel\">\n"
"<soapenv:Header/>\n"
"<soapenv:Body>\n"
"<tem:GetCompanies>\n"
"<tem:ReqLogin>\n"
"<UserName>%@</UserName>\n"
"<Password>%@</Password> \n"
"</tem:ReqLogin>\n"
"</tem:GetCompanies>\n"
"</soapenv:Body>\n"
"</soapenv:Envelope>\n",username,password];
NSURL *url = [NSURL URLWithString:kMainURL];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"http://tempuri.org/WssServiceContract/GetCompanies" forHTTPHeaderField:@"Soapaction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
网址出来是
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tem="http://tempuri.org/"
xmlns="http://WssMobileService.Model/2012/ServiceContractDslModel">
<soapenv:Header/>
<soapenv:Body>
<tem:GetCompanies>
<tem:ReqLogin>
<UserName>something</UserName>
<Password>something</Password>
</tem:ReqLogin>
</tem:GetCompanies>
</soapenv:Body>
</soapenv:Envelope>
这是我收到的请求:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action 'http://tempuri.org/WssServiceContract/GetCompanies' 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).</faultstring></s:Fault></s:Body></s:Envelope>
我看到了一些 StackOverflow 解决方案,但似乎没有任何帮助。