帮忙提供一下.net调用php接口的列子,这个接口没有wsdl档
PHP的接口直接请求就行了.最多就是参数和返回值的格式要确定下来,就跟你掉自己后台的ajax一样的
嗯,是用的直接请求,但参数好像无效,返回来总是提示参数为空
//构造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: 这么复杂,你能看到正确的请求格式不
@吴瑞祥: 看不到,返回的结果提示 productId 是空的
soap.Append("<productId>244767</productId>");
@吴瑞祥: 刚问了那边的开发
$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"}
@吴瑞祥: 已经可以了,格式的问题,那边接收的productId的格式是json的格式