Dev*_*per 14 .net c# soap web-services
我实例化HttpWebRequest对象:
HttpWebRequest httpWebRequest =
WebRequest.Create("http://game.stop.com/webservice/services/gameup")
as HttpWebRequest;
Run Code Online (Sandbox Code Playgroud)
当我将数据"发布"到此服务时,服务如何知道将数据提交到哪个Web方法?
我没有这个Web服务的代码,我所知道的是它是用Java编写的.
Jus*_*tin 18
这有点复杂,但它是完全可行的.
您必须知道要采用的SOAPAction.如果你不这样做,你就无法提出要求.如果您不想手动设置它,可以向Visual Studio添加服务引用,但您需要知道服务端点.
以下代码用于手动SOAP请求.
// load that XML that you want to post
// it doesn't have to load from an XML doc, this is just
// how we do it
XmlDocument doc = new XmlDocument();
doc.Load( Server.MapPath( "some_file.xml" ) );
// create the request to your URL
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( Your URL );
// add the headers
// the SOAPACtion determines what action the web service should use
// YOU MUST KNOW THIS and SET IT HERE
request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );
// set the request type
// we user utf-8 but set the content type here
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "POST";
// add our body to the request
Stream stream = request.GetRequestStream();
doc.Save( stream );
stream.Close();
// get the response back
using( HttpWebResponse response = (HttpWebResponse)request.GetResponse() )
{
// do something with the response here
}//end using
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
33312 次 |
最近记录: |