php调C#写的WebService参数问题

家有萌宝V 2018-06-29 07:13:34
最近一个项目要用到WebService,A端是php写的, B端是C#写的,现在A端通过SOAP调B端的接口Hello(测试方法),B端那边的人说没有参数传进来, 但是A端确实是收到返回值了,折腾了很久,用wireshark抓包分析,和正常调用(php调自己的php接口)对比,发现了一些差异,贴图如下:


php调php(正常)抓包的数据:

php调php(正常)调用时的代码:

$client = new SoapClient(null, array(
'location' => "http://172.30.34.102:8080/WebService/Service.php",
'uri' => "http://172.30.34.102:8080/WebService/Service.php",
'trace' => 1 ));
$client->Hello("jybgxt","admin","13340397452", "test");

———————————————————分割线———————————————————————
php调C#(失败)时抓包的数据

php调C#(失败)时调用的代码
$this->soap_client = new SoapClient("http://172.30.35.108/dxptfb/WebService1.asmx?wsdl");
$this->soap_client->Hello("jybgxt","admin","13340397452", "test");


经对比,B端是php时,参数是4个; 而B端换成c#时,抓包的参数是3个,见图。
由此可知,肯定是某个地方出了问题,导致参数丢失。但是至今未找到原因,期待高人指出

...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
家有萌宝V 2018-06-30
  • 打赏
  • 举报
回复
引用 5 楼 xuzuning 的回复:
由 [1] => HelloResponse Hello(Hello $parameters)
可知 Hello 方法需要一个 Hello 类型的参数


[2] => struct Hello {
string name;
string pwd;
string phones;
string content;
}
可知,Hello 是这样的关联数组【结构(struct)在 php 中表述为关联数组】
$param = array(
'name' => '值',
'pwd' => '值',
'phones' => '值',
'content' => '值',
);
这样调用 $client->Hello($param);

$client->__call('Hello', array($param));
$client->__soapcall('Hello', array($param));

这是约定,没有为什么


引用 5 楼 xuzuning 的回复:
由 [1] => HelloResponse Hello(Hello $parameters)
可知 Hello 方法需要一个 Hello 类型的参数


[2] => struct Hello {
string name;
string pwd;
string phones;
string content;
}
可知,Hello 是这样的关联数组【结构(struct)在 php 中表述为关联数组】
$param = array(
'name' => '值',
'pwd' => '值',
'phones' => '值',
'content' => '值',
);
这样调用 $client->Hello($param);

$client->__call('Hello', array($param));
$client->__soapcall('Hello', array($param));

这是约定,没有为什么


测试了一下, 可以了。 看来是必须要按照这个约定调用。 再不解决,我就要把B端的人整得抓狂了, 很开心, 分全部都给你
家有萌宝V 2018-06-30
  • 打赏
  • 举报
回复
看到希望了 我这就试试去
xuzuning 2018-06-30
  • 打赏
  • 举报
回复
由 [1] => HelloResponse Hello(Hello $parameters)
可知 Hello 方法需要一个 Hello 类型的参数


[2] => struct Hello {
string name;
string pwd;
string phones;
string content;
}
可知,Hello 是这样的关联数组【结构(struct)在 php 中表述为关联数组】
$param = array(
'name' => '值',
'pwd' => '值',
'phones' => '值',
'content' => '值',
);
这样调用 $client->Hello($param);

$client->__call('Hello', array($param));
$client->__soapcall('Hello', array($param));

这是约定,没有为什么
家有萌宝V 2018-06-30
  • 打赏
  • 举报
回复
引用 3 楼 xuzuning 的回复:
$sc = new SoapClient("http://172.30.35.108/dxptfb/WebService1.asmx?wsdl");
print_r( $sc->__getFunctions ());
print_r($sc->__getTypes () );
看看就知道

Array
(
[0] => HelloWorldResponse HelloWorld(HelloWorld $parame
[1] => HelloResponse Hello(Hello $parameters)
[2] => dxptsubmitResponse dxptsubmit(dxptsubmit $parame
[3] => HelloWorldResponse HelloWorld(HelloWorld $parame
[4] => HelloResponse Hello(Hello $parameters)
[5] => dxptsubmitResponse dxptsubmit(dxptsubmit $parame
)
Array
(
[0] => struct HelloWorld {
}
[1] => struct HelloWorldResponse {
string HelloWorldResult;
}
[2] => struct Hello {
string name;
string pwd;
string phones;
string content;
}
[3] => struct HelloResponse {
string HelloResult;
}
[4] => struct dxptsubmit {
string message;
}
[5] => struct dxptsubmitResponse {
string dxptsubmitResult;
}
)

____________________________________________________________________
以上是getFunction getType返回的
xuzuning 2018-06-30
  • 打赏
  • 举报
回复
$sc = new SoapClient("http://172.30.35.108/dxptfb/WebService1.asmx?wsdl");
print_r( $sc->__getFunctions ());
print_r($sc->__getTypes () );
看看就知道
家有萌宝V 2018-06-29
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
至少需要 $client->Hello(["jybgxt","admin","13340397452", "test"]);

具体要根据 WSDL 决定


没看懂, 用数组把参数裹起来?
xuzuning 2018-06-29
  • 打赏
  • 举报
回复
至少需要 $client->Hello(["jybgxt","admin","13340397452", "test"]);

具体要根据 WSDL 决定

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧