【问题标题】:Using SVC webservices in Objective-C (iPhone)在 Objective-C (iPhone) 中使用 SVC Web 服务
【发布时间】:2011-09-19 13:09:45
【问题描述】:

我正在尝试让我的 iPhone 应用程序连接到我的 Web 服务。我对这个 Web 服务没有太多经验,所以这就是我在这里寻求信息/帮助的原因。

我第一次尝试来回发送 XML 文件,这需要太多时间。现在我发现有一个应用程序叫:wsdl2objc。它会生成一些目标 C 文件,但我不知道如何使用它。

有人能把我推向正确的方向吗?

下面是我在浏览器中打开的 SVC 文件之一!

Metadata Service

You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://server/SB2/services/Metadata.svc?wsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:


C#

class Test
{
    static void Main()
    {
        entitiesClient client = new entitiesClient();

        // Use the 'client' variable to call operations on the service.

        // Always close the client.
        client.Close();
    }
}


Visual Basic

Class Test
    Shared Sub Main()
        Dim client As entitiesClient = New entitiesClient()
        ' Use the 'client' variable to call operations on the service.

        ' Always close the client.
        client.Close()
    End Sub
End Class

生成de源代码后不想编译:

- (BasicHttpBinding_entitiesBindingResponse *)RetrieveUsing;
- (void)RetrieveAsyncUsing delegate:(id<BasicHttpBinding_entitiesBindingResponseDelegate>)responseDelegate;
- (BasicHttpBinding_entitiesBindingResponse *)DefinedEntitiesUsing;
- (void)DefinedEntitiesAsyncUsing delegate:(id<BasicHttpBinding_entitiesBindingResponseDelegate>)responseDelegate;

错误:

error: expected ';' before 'delegate'

【问题讨论】:

    标签: iphone objective-c ios web-services soap


    【解决方案1】:

    首先,只需将生成的文件复制到您的项目中。假设你的服务叫ClientService,操作是ClientOperation,应该有一个对应名字的类(ClientService.m)v——这是你的起点。

    wsdl2objc 根据 wsdl 生成必要的绑定以及数据类。如果您的服务确实需要任何参数,您应该能够相应地设置请求实例。

    ClientServiceSOAPBinding * binding = [[[ClientServiceSOAPBinding alloc] initWithSOAPAddress:kSOAPServiceEndPoint] autorelease]; 
    typens_ClientServiceRequest *request = [[ClientServiceRequestRequest new] autorelease];
    ClientServiceSOAPBindingResponse *responseObj = [binding ClientOperationUsingPayload:request];
    

    responseObj 现在应该保存来自您的 Web 服务的响应。希望对你有帮助,

    干杯。

    编辑:

    我们后来发现,如果属性名称中有一个“点”(例如 xs:element name="Foo.Bar"),则 wsdl2objc 生成器不会替换该点,并且生成的 ivars 包含完全相同的点 - 代码中充满了语法错误,无法编译。

    【讨论】:

    • 嗯,我似乎一开始就无法让它工作!我在项目配置中配置了两个步骤,现在我通过编译得到了这个:expected identifier or '(' before '[' token
    • 我编辑了我的第一篇文章,其中一段代码给出了这个错误!
    • 你能标出错误所在的行吗?编辑:您的源代码中 RetrieveAsyncUsing 和 'delegate' 之间是否有“空格”,或者这是一个复制粘贴错误?如果是前者,请尝试删除它们。
    • 嗯,有空格...我把它改成了:,这似乎有帮助。如果我给你一个指向我原始生成文件的链接,是否有可能帮助我找到好的方向?如果是这样,请访问 www.karper-forum.com/Metadata.zip!到目前为止谢谢你:)
    • 当然。您应该从BasicHttpBinding_entities *binding = [[BasicHttpBinding_entities alloc] initWithAddress:@"http://yourserver:1234/foo"]; 开始,然后尝试使用BasicHttpBinding_entitiesResponse *response = [req RetrieveUsing]; 调用您的ws 这应该同步执行,如果它有效,也许尝试- (void)RetrieveAsyncUsing delegate:(id&lt;BasicHttpBinding_entitiesResponseDelegate&gt;)responseDelegate; 使用非阻塞异步方法。
    猜你喜欢
    • 1970-01-01
    • 2010-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 2012-04-15
    相关资源
    最近更新 更多