Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从C调用soap服务#_C#_Php_Web Services_Soap - Fatal编程技术网

C# 从C调用soap服务#

C# 从C调用soap服务#,c#,php,web-services,soap,C#,Php,Web Services,Soap,我有可以工作的PHP代码,它调用了SOAP服务,并且可以工作。其内容如下: <?php try { $client = new SoapClient(null, array( 'location' => "http://108-168-196-91.mycitrixdemo.net/zdm/services/EveryWanDevice?wsdl", 'uri' => "http://zdemo2.zenprise.com",

我有可以工作的PHP代码,它调用了SOAP服务,并且可以工作。其内容如下:

<?php
try
{
    $client = new SoapClient(null, array(
        'location' => "http://108-168-196-91.mycitrixdemo.net/zdm/services/EveryWanDevice?wsdl",
        'uri' => "http://zdemo2.zenprise.com",
        'login' => "Admin",
        'password'=> "XXXXX"));

    $properties=$client->getDeviceProperties("XXXXXXXX",null);

    for($i=0;$i<count($properties);$i++) {
        printf ("name: %s, value: %s\n" , $properties[$i]->name, $properties[$i]->value);
    }
}
catch (Exception $e)
{
    print_r($e); exit;
}
?>
我现在提供了代理类,但我不知道如何设置它们,以便调用此服务

我在C#中的操作如下:

但是
srv.authenticateUser
行抛出以下异常:

RPC Message getDeploymentHistoRequest1 in operation getDeploymentHisto1 has an invalid body name getDeploymentHisto. It must be getDeploymentHisto1

我不知道这个错误是什么意思。有人能帮忙吗?

这是因为使用了WCF参考而不是标准服务参考

看一看,以便进一步讨论

简而言之,在添加服务参考的高级页面上使用添加Web参考:


在我看来,此错误似乎是生成代理文件时出现的问题。您可能希望使用重新代理以确保正确生成代理文件。在您的情况下,VisualStudioDeveloper命令工具中的命令如下所示

svcutil.exe /language:cs /out:Proxies.cs /config:output.config [service url]
var srv = new DeviceServiceClient();

srv.ClientCreditials.UserName.UserName = "Admin";
srv.ClientCreditials.UserName.Password = "XXXXX";
看起来你一开始并不是在建立一个安全的会话。将您的绑定更改为以下内容

<binding name="EveryWanDeviceSoapBinding" 
         closeTimeout="00:01:00" 
         openTimeout="00:01:00" 
         receiveTimeout="00:10:00" 
         sendTimeout="00:01:00" 
         allowCookies="false" 
         bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard" 
         maxBufferSize="6553666" 
         maxBufferPoolSize="524288" 
         maxReceivedMessageSize="6553666" 
         messageEncoding="Text" 
         textEncoding="utf-8" 
         transferMode="Buffered" 
         useDefaultWebProxy="true">
    <security mode="Transport">
        <transport clientCredentialType="Basic" 
                   proxyCredentialType="Basic" 
                   realm="" />
        <message clientCredentialType="UserName" 
                 algorithmSuite="Default" />
    </security>
</binding>
最后,您可以使用参数调用
getDeviceProperties
方法,并获得某种响应

<binding name="EveryWanDeviceSoapBinding" 
         closeTimeout="00:01:00" 
         openTimeout="00:01:00" 
         receiveTimeout="00:10:00" 
         sendTimeout="00:01:00" 
         allowCookies="false" 
         bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard" 
         maxBufferSize="6553666" 
         maxBufferPoolSize="524288" 
         maxReceivedMessageSize="6553666" 
         messageEncoding="Text" 
         textEncoding="utf-8" 
         transferMode="Buffered" 
         useDefaultWebProxy="true">
    <security mode="Transport">
        <transport clientCredentialType="Basic" 
                   proxyCredentialType="Basic" 
                   realm="" />
        <message clientCredentialType="UserName" 
                 algorithmSuite="Default" />
    </security>
</binding>
var srv = new DeviceServiceClient();

srv.ClientCreditials.UserName.UserName = "Admin";
srv.ClientCreditials.UserName.Password = "XXXXX";