首页 新闻 会员 周边

.net调用php

0
[已解决问题] 解决于 2016-01-21 19:15

帮忙提供一下.net调用php接口的列子,这个接口没有wsdl档

jhkmnm的主页 jhkmnm | 初学一级 | 园豆:19
提问于:2014-04-18 12:43
< >
分享
最佳答案
0

PHP的接口直接请求就行了.最多就是参数和返回值的格式要确定下来,就跟你掉自己后台的ajax一样的

奖励园豆:5
吴瑞祥 | 高人七级 |园豆:29449 | 2014-04-18 13:11

嗯,是用的直接请求,但参数好像无效,返回来总是提示参数为空

//构造soap请求信息
StringBuilder soap = new StringBuilder();
soap.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
soap.Append("<soap-ENV:Envelope xmlns:soap-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
soap.Append("<soap-ENV:Body>");
soap.Append("<erp_get_tgoods>");//
soap.Append("<productId>244767</productId>");
soap.Append("</erp_get_tgoods>");
soap.Append("</soap-ENV:Body>");
soap.Append("</soap-ENV:Envelope>");

//发起请求
Uri uri = new Uri("http://xxxxxxxx/index.php?r=yar/tgoods");
WebRequest webRequest = WebRequest.Create(uri);
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Method = "POST";
using (Stream requestStream = webRequest.GetRequestStream())
{
byte[] paramBytes = Encoding.UTF8.GetBytes(soap.ToString());
requestStream.Write(paramBytes, 0, paramBytes.Length);
}

HttpWebResponse res;
try
{
res = (HttpWebResponse)webRequest.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
string strHtml = sr.ReadToEnd();

jhkmnm | 园豆:19 (初学一级) | 2014-04-18 15:06

@jhkmnm: 这么复杂,你能看到正确的请求格式不

吴瑞祥 | 园豆:29449 (高人七级) | 2014-04-18 15:52

@吴瑞祥: 看不到,返回的结果提示 productId 是空的

soap.Append("<productId>244767</productId>");  

jhkmnm | 园豆:19 (初学一级) | 2014-04-18 16:04

@吴瑞祥: 刚问了那边的开发

$client = new SoapClient(NULL, array(
'location' => "http://manage.myefox.com/index.php?r=yar/tgoods",
'uri' => "http://manage.myefox.com"
)
);

$param = json_encode(array('productId' => 'MHC2'));
$result = $client->erp_get_tgoods($param);

他们是这样测试的,$param的值是 {"productId":"MHC2"}

jhkmnm | 园豆:19 (初学一级) | 2014-04-18 16:07

@吴瑞祥: 已经可以了,格式的问题,那边接收的productId的格式是json的格式

jhkmnm | 园豆:19 (初学一级) | 2014-04-18 16:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册