使用C#调用Axis Web服务 [英] Call Axis web service using c#

查看:116
本文介绍了使用C#调用Axis Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在使用C#调用Axis2 Web服务时遇到问题.
当我通过SOAP工具调用此服务时,它的工作正常.
但是通过c#代码,它会给内部服务器错误.

请告诉我在致电服务时我缺少什么.
如何在C#代码中添加username/pwd和timestamp属性.

我试图在VS 2008中使用添加引用"来调用它,并使用WSDL实用程序成功创建了代理
但仍然无法致电该服务.
这是我的示例代码

Hi All,

I am having problem in calling Axis2 web service using C#.
When i call this service through SOAP tool its working fine.
But through c# code its giving Internal Server Error.

Please tell me what i am missing while calling the service.
How can i add the username/pwd and timestamp property in c# code.

I tried to call this using Add Reference in VS 2008 and i successfully create proxy using WSDL utility
but still i am unable to call the service.
here is my sample code

string soap = BuildAxisSOAPMessage("", "crm", "get"); // Create SOAP Message using this function
            soap = soap.Replace("", "");
            HttpWebRequest request;
            request = (HttpWebRequest)WebRequest.Create("http://**********/********/***/****Service?wsdl");
            request.Headers.Add("Username", "******");
            request.Headers.Add("Password", "*******");
            request.Headers.Add("Nonce", "*******");
            request.Headers.Add("Created", DateTime.Now.ToUniversalTime().ToString());
            request.Headers.Add("Timestamp", DateTime.Now.ToUniversalTime().ToString());
            request.Credentials = new NetworkCredential("*****", "******");
            request.Method = "POST";
            request.Headers.Add("SOAPAction", "urn:get");
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(soap);
            using (Stream postStream = request.GetRequestStream())
            {
                postStream.Write(byte1, 0, byte1.Length);
            }

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) // Gives error-- Internal server Error..
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string res = reader.ReadToEnd();
            }



在此先感谢

Nitin



Thanks in advance

Nitin

推荐答案

在这种情况下,您可以使用wsdl工具(从VS2008命令提示符运行). wsdl帮助使用ASP.NET为Web服务客户端生成代码.您可以在客户端(Web服务调用)代码中添加此代理类. wsdl的语法是:

In this scenario, you can use wsdl tool (Run it from VS2008 command prompt). wsdl helps to generate code for web service client using ASP.NET. You can add this proxy class in your client (web service calling) code. Syntax of wsdl is:

wsdl.exe <options> <url or="" path="">..</url></options>



wsdl/? |更多(有关更多帮助信息)



wsdl /? | more (for more help info)


Hello Friend ..

尝试使用jquery和ajax调用您的Web服务.
像这样..
Hello Friend..

Try to call your webservice using jquery and ajax.
like this..


.ajax({ 类型:" , url:" , 数据:" contentType:" , dataType:" , beforeSend:功能(){您的发送前条件}, 完成:功能(){您完成的条件}, 成功:功能(msg){ // msg.d包含返回的JSON }, 错误:功能(){} });
.ajax({ type: "POST", url: "your webservice url with calling function name", data: "{your parameter list with value}" contentType: "application/json; charset=utf-8", dataType: "json", beforeSend: function () { your before send criteria }, complete: function () { your after completed criteria }, success: function (msg) { //msg.d contains the returned JSON }, error: function () { } });




有关此的更多详细信息,请参见此链接..

如何使用ASP.NET AJAX从客户端JavaScript调用Web服务 [




for more detail on this see this links..

How to call a Web Service from client-side JavaScript using ASP.NET AJAX[^]


这篇关于使用C#调用Axis Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆