Получение ошибки SOAP при запросе веб-службы WCF в Objective C (приложение для iOS) - PullRequest
0 голосов
/ 22 ноября 2011

Я пытаюсь вызвать веб-сервис из приложения iOS.Я разработал этот сервис в WCF.Веб-служба размещена на IIS, настроенном с BasicHTTPBinding.Я разработал простое приложение для iOS, которое вызывает этот веб-сервис, размещенный на удаленном ПК.

Приложение iOS работает нормально, но служба SOAP, похоже, не понимает запрос, который я отправляю из приложения iOS.Вот все детали, ошибка, которую я получаю, находится в конце.

WSDL веб-сервиса:

    <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" name="SLService" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://10.211.55.4/TestService/SLService.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://10.211.55.4/TestService/SLService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ISLService_DoWork_InputMessage">
<wsdl:part name="parameters" element="tns:DoWork"/>
</wsdl:message>
<wsdl:message name="ISLService_DoWork_OutputMessage">
<wsdl:part name="parameters" element="tns:DoWorkResponse"/>
</wsdl:message>
<wsdl:portType name="ISLService">
<wsdl:operation name="DoWork">
<wsdl:input wsaw:Action="http://tempuri.org/ISLService/DoWork" message="tns:ISLService_DoWork_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISLService/DoWorkResponse" message="tns:ISLService_DoWork_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_ISLService" type="tns:ISLService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="DoWork">
<soap:operation soapAction="http://tempuri.org/ISLService/DoWork" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SLService">
<wsdl:port name="BasicHttpBinding_ISLService" binding="tns:BasicHttpBinding_ISLService">
<soap:address location="http://10.211.55.4/TestService/SLService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Вот как я делаю запрос SOAP в iOS,проблема, скорее всего, здесь:

NSString *soapMessage = [NSString stringWithFormat:@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><DoWork></DoWork></SOAP-ENV:Body></SOAP-ENV:Envelope>"];

NSURL *url=[NSURL URLWithString:@"http://10.211.55.4/TestService/SLService.svc/"];

NSMutableURLRequest *theRequest= [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"urn:SLService/DoWork" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];    
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if (theConnection) {

    responseData = [[NSMutableData data] retain];
} else {

    messageTextView.text=@"Failed";

}

Вот что находится внутри класса веб-службы WCF:

namespace TestSilverlight.Web{

public class SLService : ISLService
{
    public string DoWork()
    {
        return "Service Works!";
    }
}}

Вот содержимое файла web.config в веб-службе WCF:

    <?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    </system.serviceModel>
</configuration>

Вот ответ SOAP (ошибка), который я получаю в объекте responseData:

a: ActionNotSupported. Сообщение с действием 'urn: ISLService / DoWork' не может быть обработано в получателе, из-за несоответствия ContractFilter в EndpointDispatcher.Это может быть связано либо с несоответствием контракта (несоответствующие действия между отправителем и получателем), либо с несоответствием привязки / безопасности между отправителем и получателем.Убедитесь, что отправитель и получатель имеют один и тот же контракт и одну и ту же привязку (включая требования безопасности, например, Message, Transport, None).

Я сосу, задавая вопросы здесь, надеюсь, вы, ребята, понимаете это.Пожалуйста, помогите.

1 Ответ

2 голосов
/ 23 ноября 2011

Проблема с вашим заголовком SOAPAction. Я подозреваю, что проблема такая же, как этот вызов wcf webservice с использованием basichttpbinding без REST или JSON .

Решение будет изменить ваш SOAPAction с

urn:SLService/DoWork

до

http://tempuri.org/SLService/DoWork

или, может быть, даже

http://tempuri.org/ISLService/DoWork
...