post方式调用带[SoapHeader("header")]的webservice方法 40C

想做一个webservice身份验证,服务端通过用户名和密码验证客户端是否有权

限访问该接口。
下面是网上找的用c#写的服务端代码,我不想用添加引用的方式调用,请问
用post方式调用webservice,如何将客户端的username和password传到SoapHeader中呢,代码该怎么写呢?

//类

public class CustomSOAPHeader : SoapHeader  {

public CustomSOAPHeader()
{

}   

public string name;

public string password;

//这是方法
public bool IsValid
(string strUserName, string strPassword)

{

if
(strUserName == "admin" && strPassword == "admin")

return true;

else   

return false;   

} 

}

public CustomSOAPHeader header;

[SoapHeader("header")]

[WebMethod(Description = "测试", EnableSession = true)]

public string GetProduct(string Id)

{

if
(header.IsValid(header.name, header.password))   

return "验证成功";   

return "验证失败";

}

c#

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
android调用带soapheader的webservice
android调用带soapheader的webservicernrn SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(rn SoapEnvelope.VER11);rn Element[] header = new Element[1];rn header[0] = new Element().createElement(NameSpace, "header");rn Element username = new Element().createElement(NameSpace,rn "Username");rn username.addChild(Node.TEXT, "admin");rn header[0].addChild(Node.ELEMENT, username);rn Element pass = new Element().createElement(NameSpace, "Password");rn pass.addChild(Node.TEXT, "123");rn header[0].addChild(Node.ELEMENT, pass);rnrn envelope.headerOut = header;rn // 设置是否调用的是dotNet下的WebServicern envelope.dotNet = true;rn // 必须,等价于envelope.bodyOut = request;rn envelope.setOutputSoapObject(request);rn // step4 创建HttpTransportSE对象rn AndroidHttpTransport ht = new AndroidHttpTransport(this.finalUrl);rn关键代码不对那 webservice那边rnrn Element token = context.getInMessage().getHeader().getChild(rn WebserviceConstant.TOKEN);rn接受到的空值啊 请问高手给看看
调用webservice的soapheader问题
public void test()rnrnStringBuilder soap = new StringBuilder();rn soap.Append("");rn soap.Append("");rn soap.Append("");rn soap.Append("");rn soap.Append("admin");rn soap.Append("admin123");rn soap.Append("");rn soap.Append("");rn soap.Append("");rn soap.Append("");rn soap.Append("");rn soap.Append("");rn soap.Append("");rn //Uri uri = new Uri("http://www.webxml.com.cn/WebServices/WeatherWS.asmx");rn Uri uri = new Uri(strURL);rn WebRequest webRequest = WebRequest.Create(uri);rn webRequest.ContentType = "text/xml; charset=utf-8";rn webRequest.Method = "POST";rn using (Stream requestStream = webRequest.GetRequestStream())rn rn byte[] paramBytes = Encoding.UTF8.GetBytes(soap.ToString());rn requestStream.Write(paramBytes, 0, paramBytes.Length);rn rn rn //响应rn WebResponse webResponse = webRequest.GetResponse();rn using (StreamReader myStreamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))rn rn Console.WriteLine(myStreamReader.ReadToEnd());rn rnrn Console.ReadKey()rnrn我用了上面的代码调用webservice,但现在服务器端加了验证,需要在soapheader里增加用户名和密码的信息才能访问到方法,我试了如上代码,但报500错误,不知为什么:(
WebService SoapHeader 身价验证方式
我在网络上看了许多SoapHeader身份验证方式rn发现都有一个示例rnWebService都写的好好的rn就是客户端不知道要怎么调用了rnrnrn网上教程的客户端调用代码:rn IssueVisionServices dataService = new IssueVisionServices(); rn CredentialSoapHeader header = new CredentialSoapHeader(); rn header.Username = username; rn header.Password = password; rn dataService.CredentialSoapHeaderValue = header; rn不知道其中使用的IssueVisionServices是何种调用方式,rnrn我是用自动生成的客户端代理类为调用的,怎么也找不到CredentialSoapHeaderValue 属性。
post方式,header对接接口
利用https://app.netease.im/index#/网站接口,制作手机发送验证码 public function phone(){         //发送到的目标手机号码 $telphone         $telphone = $_GET['phone'];         $appSecret = 'cbb9799a43b6';         $CurTim
C#调用Axis2发布的带SoapHeader用户验证的WebService
C#调用Axis2发布的带SoapHeader用户验证的WebService   环境: 提供的服务是Axis2开发的,我方用C#调用,开发环境是VS2010     起因: 合作公司提供了一个WebService供我调用,为了保证安全性,要求在SoapHeader中带用户名和密码进行校验。 在获取了对方的WSDL文件后,并未在文件中指明SoapHeader的格式以及要传递的用户名、...
.net调用JAVA带SoapHeader验证的WebService问题
用.net调用JAVA带SoapHeader验证的WebService问题,JAVA作为服务端,当然只提供一个带“?wsdl”的URLrn如果通过添加Web引用方式,然后手动修改代理类的方式调用,现在已经实现了rn但是这样有个问题,就是服务端地址变了,就得更新Web引用,然后重新修改代理类....rn现在别人提供另一种方式,如下步骤:rn1、用WSDL命令将URL编译成本地.cs;rn2、然后修改.cs文件(给.cs文件加标头,就是加SoapHeader的一些东西)rn3、再用csc命令将其编译成dll文件来调用rn(注意以上步骤都是通过c#代码来实现)rnrn现在第2步的这个给.cs文件加标头,我不知道怎么实现(应该不是用读写文件的方式来实现吧)。rn哪位做过的给指导下。。rn
使用Http post的方式调用webservice
在不能引用其他jar包的情况调用webservice有时可以解决jar引用和冲突的问题
HTTP POST方式调用WebService的问题。
现有C#开发的WebService下的一个方法:rn [WebMethod]rn public int TestByteArray(string strIn, byte[] strRequest)rnrn // 相关实现rn return 0;rnrnrn目前准备使用HTTP POST方式调用该方法,请问该如何写代码?rn用HttpPost类操作的话,这个byte[]不知道该如何传递。rnrnrn还请大虾支招。rnrnPS: 回复使用SOAP方式调用的就别浪费时间回复了,用KSOAP2我也知道调用。rnrn下面提供一个网上找到的单个参数传递byte[]的方式, 多个参数中,带有byte[]的就搞不定了:rnrn[code=Java]public boolean post(byte[] paramArrayOfByte,String http)rnrn  rnrn  ByteArrayEntity arrayEntity=new ByteArrayEntity(paramArrayOfByte);rnrn  arrayEntity.setContentType("application/octet-stream");rnrn  HttpPost httpPost=new HttpPost(http);rnrn  httpPost.setEntity(arrayEntity);rnrn  DefaultHttpClient client=new DefaultHttpClient();rnrn  try rnrn  int result=client.execute(httpPost).getStatusLine().getStatusCode();rnrn  Log.i("XXXXXXXXXXXXXXX", result);rnrn   catch (Exception e) rnrn  throw new RuntimeException(e);rnrn  rnrn  return false;rnrn  [/code]
.net Post方式调用.net和java的webservice
.net Post方式调用.net和java的webservice,用post方式提交xml请求
dephi调用基于soapheader认证的webservice(c#)
如题
WebService安全性之SoapHeader
WebService安全性SoapHeader 运行环境 VS2010
BCB6如何调用带有SoapHeader认证的Webservice
webservice是C#.net写的~rnC++bulider6.0调用rn目前问题是C++Bulider6.0WSDL引导生成的代码里没有soapheader定义相关的东西rn看了下Delphi下能实现WebService带身份认证的数据传输~rn相信BCB应该还是可以~
SOAPHEADER方法增强WebService安全性代码
示例包括利用SoapHeader方法控制Web Service接口安全性的服务端及客户端调用完整调用程序,实现简单,有说明!
C#静态调用带有SoapHeader验证的WebService
关于此代码的使用及相关配置,可以见此文:http://blog.csdn.net/u012995964/article/details/54562111 代码开发时环境:Windows8.1、Visual Studio 2013、IIS8 注意:测试代码时,重新部署WebService服务且修改客户端测试程序的服务引用
delphi6调用WebService(C#)如何传递SoapHeader
delphi6调用WebService(C#)如何传递SoapHeader?
webservice 应用的问题(vb6调用,soapheader)
服务器端用的是.net2005开发的很简单,用c#.net调用一点问题也没有,但vb6就不那么听话了。问题并不是因为vb6读取不到WebService方法,而是WebService进行加密后vb6的soapheader就不知道怎么用了rnrn以下为服务器端的代码(测试地址:"http://127.0.0.1/webtest/WebService.asmx")rnrnCredentials.csrn[code=C#]using System;rnusing System.Web.Services.Protocols;rnrnnamespace TestWebServicernrn public class Credentials:SoapHeaderrn rn public string Name;rn public string Password;rn rnrn[/code]rnrnWebService.asmx 的代码为rn[code=C#]rnusing System;rnusing System.Data;rnusing System.Web;rnusing System.Collections;rnusing System.Web.Services;rnusing System.Web.Services.Protocols;rnusing System.ComponentModel;rnusing TestWebService;rnrnnamespace Webrnrn /// rn /// WebService 的摘要说明rn /// rn [WebService(Namespace = "http://tempuri.org/")]rn [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]rn [ToolboxItem(false)]rn public class WebService : System.Web.Services.WebServicern rnrn public WebService()rn rn rnrnrn public Credentials token;rn [WebMethod(Description = "带soap头的webservice")]rn [SoapHeader("token", Direction = SoapHeaderDirection.In)]rn public string HelloWorld(string username)rn rn string name = username;rn if (token.Name == "admin" && token.Password == "123")rn rn return "Hello World" + username;rn rn elsern rn throw new ApplicationException("Authentication Failed!");rn rn rn [WebMethod]rn public string GetTest(string str)rn rn return "test"+"--"+str;rn rn rnrnrn[/code]rnrnrn在.net的客户端调用rn[code=C#]using System;rnusing System.Collections.Generic;rnusing System.Text;rnrnnamespace testrnrn public class MainClassrn rn static void Main()rn rn Console.Write(web());rn Console.ReadLine();rn rn public static string web()rn rn localhost.WebService myweb = new test.localhost.WebService();rn localhost.Credentials token = new test.localhost.Credentials();rn token.Name = "admin";rn token.Password = "123";rn myweb.CredentialsValue = token;rn tryrn rn return myweb.HelloWorld("hello");rn rn catchrn rn return ":(";rn rn rn rn[/code]rnrn以上是c#.net调用是没有问题的rnrn-------------------------------------------------------------------------------rn接下来是用vb6来调用rn[code=VB]rnOption Explicitrn'webservice 地址rnPrivate Const wsurl = "http://127.0.0.1/webtest/WebService.asmx?wsdl"rnrn'btn1_Click调用webservice的方法没有进行加密rnPrivate Sub btn1_Click()rnDim soapclient3 As New SoapClient30rnsoapclient3.mssoapinit (wsurl)rnMsgBox (soapclient3.GetTest("ReturnString"))rnEnd Subrnrn'btn2_Click调用webservice的HelloWorld方法rnPrivate Sub btn2_Click()rnDim soapclient3 As New SoapClient30rnsoapclient3.mssoapinit (wsurl)rn'试了很多方法,实在不知道怎么样添加HeaderHandler rn'soapclient3.HeaderHandler rnMsgBox (soapclient3.HelloWorld("hello"))rnEnd Subrn[/code]rn[color=#FF0000]rn有谁知道针对我用.net写的服务端,用vb6来调用HelloWorld的方法[/color]
pb调用webservice如何使用SoapHeader
用pb9调用别的公司的webservice时,对方处于安全考虑,做了SoapHeader的身份认证,找了好多资料,好象没有这个方面的,有人知道怎么用吗?
【Webservice】客户端调用设置header
之前调用其它系统的webservice接口,都是直接下载客户端,然后根据wsdl文档进行开发 但是这次调用erp系统的接口需要设置header,本来才soapUI测试没什么问题,但是用代码实现就出了问题 因为它不是写在envelope里面,而是直接在请求中的header中,尝试了很多方法,最终实现了,不过其他的尝试或许下次也可以用,特此记录
WebService加密 for SoapHeader
对WebService安全访问,用SoapHeader加密! 案例里面, 有申明跟如何调用的例子
webservice的soapHeader问题
[code=csharp]rn DataSoapHeader header = new DataSoapHeader();rn header.UserName = "xxx";rn header.PassWord = "xxx";rn OrdersWebService orderWebservice = new OrdersWebService();rn orderWebservice.myHeader = header;rn XmlNode x = orderWebservice.CreateOrderAndGetData("");rn[/code]rn代码里这么写可以调用webservicernrn但在浏览器里调用呢?浏览器里只有输入参数的文本框,有没有输入SoapHeader的地方,直接调用就失败了。。rn[img=http://img.my.csdn.net/uploads/201304/11/1365650909_5827.png][/img]rn有办法浏览器查看么?rn
Webservice的 post方法
# region 创建HttpWebRequest对象rn string service = "http://localhost/WMSFMIS/WMSFMIS.asmx/GetMapExtended";rn HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(service);rn #endregionrn rn #region 给HttpWebRequest对象赋值rn string contenttype = "application/x-www-form-urlencoded";rn string para= "UserRequest=VERSION=1.3.0&REQUEST=GetMapExtended&Layers=rnDq,Dqboundary,DqLabel&STYLES=&CRS=EPSG:21413&BBOX=-176102.69,174551.45,270467.229,490514.5&FORMAT=image/png&WIDTH=1024&HEIGHT=768&ACTIVELAYER=Dq";rn myRequest.Headers.Add(String.Format("SOAPAction: \"0\"","Web Service based Web Map Service used for FMIS/GetMapExtended"));rn myRequest.Method = "POST";rn myRequest.ContentType = contenttype;rn myRequest.ContentLength = para.Length;rn Stream newStream = myRequest.GetRequestStream();rn ASCIIEncoding encoding = new ASCIIEncoding();rn byte[] postdata = encoding.GetBytes(para);rn newStream.Write(postdata, 0, para.Length);rn newStream.Close();rn #endregionrnrn HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();rn StreamReader reader = new StreamReader(myResponse.GetResponseStream());rn string content = reader.ReadToEnd();//得到结果 rn 编译的时候没有错误。rn得到的content结果如下:rnrn rn- rn Required parameter REQUEST not specified rn rn请问问题出在什么地方?rn附:[color=#FF0000]HTTP POSTrnThe following is a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.rnrnPOST /WMSFMIS/WMSFMIS.asmx/GetMapExtended HTTP/1.1rnHost: localhostrnContent-Type: application/x-www-form-urlencodedrnContent-Length: lengthrnrnUserRequest=stringrnHTTP/1.1 200 OKrnContent-Type: text/xml; charset=utf-8rnContent-Length: lengthrnrnrnbase64Binary rn iVBORw0KGgoAAAANSUhEUgAABAAAAAMACAYrnAAAC6uhUNAAAAAXNSR0IArs4crn6QAAAARnQU1BAACxjwv8YQUAAAAgrnY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAmwJJRErnFUeF7t3VuO7saytWcZ7pb[/color]
WebService和调用WebService的方法
WebService的实现方法和调用方法。
Unity3D Http网络通讯协议 带header头部的GET与POST方法:
private string authorization; private string jsonData = null;//在此案例中我假设json数据表为string 数值为null,实际上需要经过Json WriteValue的转译 void Start() { string url="http://192.168.xx.xxx/api/xxxxxxxxxxxxxxxx";//接口ur...
php之curl带头部header的post请求
public function op(){ // $url = 'http://www.baidu.com/test/na/oh'; $header=array('Accept-Language:zh-CN','x-appkey:114816004000028','x-apsignature:933931F91245938653...
使用postman进行带header的post请求
使用postman进行带header的post请求首先你得下载postman软件,下载地址自找第一步如图: 接下来选择headers 按照key,value的形式输入你所要的header 如果服务端需要请求类型为json,需要在“headers”添加 key:Content-Type , value:application/json。如图: header完成后,接下来是body,key
POST方式调用第三方接口
1.第三方接口 @RequestMapping(value = "/updatePwd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody public String GztzUpdatePwd(@RequestBody String password ...
Java调用.NET webservice方法的几种方式
一. 使用axis1.x调用webservice方法 Axis的最常用版本:1.4和2.0版本。以下为1.4版本  核心代码:   // webserviceURL       service_url = "http://vip.cxcod.com/PodApi/GetPodStr.asmx?wsdl";       Service service = new Service(...
VC++调用WebService的方式
Microsoft Visual C++调用WebService的实现代码,还包括BASE64编码方法
在webservice 服务端接收不到SoapHeader
silverlight客户端:rn[code=csharp]rn public class MyHead : MessageHeaderrn rn public string UserName get; set; rn public string Password get; set; rnrnrn protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion)rn rn writer.WriteElementString("UserName", "http://www.yourwebsite.net/", UserName);rn writer.WriteElementString("Password", "http://www.yourwebsite.net/", Password);rn rnrn public override string Namern rn get return "MyHead"; rn rnrn public override string Namespacern rn get return "http://www.yourwebsite.net"; rn rn rnrnrn client = new goodsService.goodsServiceSoapClient();rn MessageHeader head = new MyHead();rn head.UserName = "adm";rn head.Password = "123456";rn OperationContext.Current = new OperationContext(client.InnerChannel);rn OperationContext.Current.OutgoingMessageHeaders.Add(head);rnclient.getAllTasksAsync();rn[/code]rnrnwebService服务端:rn[code=csharp]rn public class MyHead : SoapHeaderrn rn public string UserName get; set; rn public string Password get; set; rn rnrnrn 下面是需要调用的方法rn public MyHead my=new MyHead();rn [WebMethod]rn [SoapHeader("my", Direction = SoapHeaderDirection.In)]rn public string getAllTasks()rn rn //为什么此处的my对象中就是没有userName的值呢,始终为null ,没有传过SoapHead头部来呢rn if ((my.UserName == "adm")rn return "";rn elsern return "error";rn rn[/code]
基于 C 语言的 JavaScript 引擎探索
点击打开链接
动态调用webservice ,怎样soapheader身份认证。
下面是相关的代码,如果您做过相关的,帮忙加Q吧1347895284,rn现在还有二百分,都给您。麻烦了。rn赋值下面的代码,然后直接搜索 zhang add ,rn这这部分里是我自己写的认证方法,反射存在问题。字数原因代码不全,见谅rnrnusing System;rnusing System.Collections.Generic;rnusing System.Linq;rnusing System.Text;rnusing System.Net;rnusing System.IO;rnusing System.Web.Services.Description;rnusing System.Xml.Serialization;rnusing System.CodeDom;rnusing System.CodeDom.Compiler;rnusing System.Reflection;rnusing System.Web.Services.Protocols;rnrnnamespace CZH.Utilrnrn /// rn ///动态调用WebServicern /// rn public class WebServiceUtilrn rn public static object CallWebService(string WebServiceURL, string AgentClassName, string MethodName, object[] Parameters, string Timeout, string DllPath, out string ErrorMsg)rn rn object Result = null;rn ErrorMsg = "";rn tryrn rn if (WebServiceURL == null || WebServiceURL == "")rn rn ErrorMsg = "WebServiceURL不能为空!";rn return null;rn rn if (MethodName == null || MethodName == "")rn rn ErrorMsg = "MethodName不能为空!";rn return null;rn rn //if (DllName == null || DllName == "")rn //rn // ErrorMsg = "DllName不能为空!";rn // return null;rn //rn if (DllPath == null || DllPath == "")rn rn ErrorMsg = "DllPath不能为空!";rn return null;rn rnrn if (Timeout == null || Timeout == "")rn rn Timeout = "60000";//默认为1分钟rn rn private static object ExecMethod(Assembly asm, string WebServiceURL, string AgentClassName, string MethodName, object[] Parameters, int Timeout, string DllName, string DllPath, bool IsUpdWebService, out string ErrorMsg)rn rn ErrorMsg = "";rn object Result = null;rn Type t = asm.GetType("mydynamiccallwebservice." + AgentClassName);rnrn #region zhang add 动态加soap头rn //Soap头开始 rn FieldInfo client = t.GetField("ClientKey");rn //获取客户端验证对象 rn Type typeClient = asm.GetType("mydynamiccallwebservice" + ".ClientKey");rn FieldInfo userName = typeClient.GetField("UserName");rn FieldInfo passWord = typeClient.GetField("PassWord");rn //为验证对象赋值 rn object clientkey = Activator.CreateInstance(typeClient);rn userName.SetValue(clientkey,"test"); //???rn passWord.SetValue(clientkey,"test"); //???rn //Soap头结束 rn #endregionrnrn object o = Activator.CreateInstance(t);rn //zhang addrn client.SetValue(o, clientkey);rn //获取方法 rn MethodInfo method = t.GetMethod(MethodName);//GetPersons是服务端的方法名称rnrn if (method == null)rn rn if (IsUpdWebService == true)//动态更新WebServicern rn // File.Delete(DllPath);//先删除此dllrn string TempStr = DllName.Substring(DllName.LastIndexOf("_") + 1);rn TempStr = TempStr.Substring(0, TempStr.LastIndexOf(".dll"));rn int DllMaxNum = Convert.ToInt32(TempStr);rnrn //给10次机会生成dll,如果还是调用不到的话,那么就代表这“方法名”在WebService里面已去除了rn if (DllMaxNum == 10)rn rn ErrorMsg = "没有此方法:" + method + ",请重新设置方法名;注意:请把此文件夹:" + DllPath + " 下面自动生成dll都删除,如果删除不了,先停了这些dll所在的宿主(比如IIS,或者当前的应用程序等)再删除此dll,不然有可能是被这宿主占用了资源删除不了!";rn return null;rn rnrn DllName = "webservice_dynamiccall_" + (++DllMaxNum).ToString() + ".dll";//原来的那个dll没法删除,因为占用了资源,没法释放资源,只有垃圾回收站释放资源了,但是又得要更新些Dll,所以重新生成另一个新的dllrnrnrn //如果method为null,那么只有两种可能:1.此类下没有此方法 2.服务器那边WebSrvice添加了新的方法,此代理类没有更新rn //所以这里处理是:第一次method为null,那么给一次机会,用下面的方法"OutputAssembly"重新更新下WebService,并重新生成dll文件rn OutputAssembly(WebServiceURL, Timeout, DllName, DllPath, out ErrorMsg);rn if (ErrorMsg != "")//代表出错了rn rn return null;rn rnrn //重新加载新的dllrn asm = Assembly.LoadFrom(DllPath + DllName);rn t = asm.GetType("mydynamiccallwebservice." + AgentClassName);rn o = Activator.CreateInstance(t);rn method = t.GetMethod(MethodName);rnrn rn //如果method还为null,那么则"MethodName"则真是错误了rn if (method == null)rn rn ErrorMsg = "没有此方法: " + MethodName;rn return null;rn rn rnrn tryrn rn //注:method.Invoke(o, null)返回的是一个Object,如果你服务端返回的是DataSet,这里也是用(DataSet)method.Invoke(o, null)转一下就行了rn Result = method.Invoke(o, Parameters);rn rn catch (Exception e)rn rnrn ErrorMsg = "参数有错误:Parameters" + e.ToString(); ;rn rn return Result;rn rnrnrn private static void OutputAssembly(string WebServiceURL, int Timeout, string DllName, string DllPath, out string ErrorMsg)rn rn ErrorMsg = "";rn tryrn rnrn HttpWebRequest client = (HttpWebRequest)HttpWebRequest.Create(WebServiceURL);rn client.Timeout = Timeout;rn rnrn Stream stream = ((HttpWebResponse)client.GetResponse()).GetResponseStream();rnrn ServiceDescription description = ServiceDescription.Read(stream);rnrn ServiceDescriptionImporter importer = new ServiceDescriptionImporter();//创建客户端代理代理类。rn rnrn importer.ProtocolName = "Soap"; //指定访问协议。rn importer.Style = ServiceDescriptionImportStyle.Client; //生成客户端代理。rn importer.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync;rnrn importer.AddServiceDescription(description, null, null); //添加WSDL文档。rnrn CodeNamespace nmspace = new CodeNamespace(); //命名空间rn nmspace.Name = "mydynamiccallwebservice";rnrn CodeCompileUnit unit = new CodeCompileUnit();rn unit.Namespaces.Add(nmspace);rnrn ServiceDescriptionImportWarnings warning = importer.Import(nmspace, unit);rn CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");rnrn CompilerParameters parameter = new CompilerParameters();rn parameter.GenerateExecutable = false;rn parameter.OutputAssembly = DllName;//输出程序集的名称rn parameter.ReferencedAssemblies.Add("System.dll");rn parameter.ReferencedAssemblies.Add("System.XML.dll");rn parameter.ReferencedAssemblies.Add("System.Web.Services.dll");rn parameter.ReferencedAssemblies.Add("System.Data.dll");rnrn CompilerResults result = provider.CompileAssemblyFromDom(parameter, unit);rn if (result.Errors.HasErrors)rn rn // 显示编译错误信息rn ErrorMsg = "动态编绎:\"" + DllName + "\"有错误!";rn rn //这里就生成了动态的dllrn File.Copy(AppDomain.CurrentDomain.BaseDirectory + DllName, DllPath + DllName);rn File.Delete(AppDomain.CurrentDomain.BaseDirectory + DllName);rn rn catch (Exception ex)rn rn ErrorMsg = "创建代理类并动态生成Dll出错:" + ex.Message + "; " + ex.StackTrace;rn rn rnrnrnrn rnrn
收藏 文本service
http://www.blogjava.net/zjhiphop/archive/2009/04/29/webservice.html
调用webservice的方式解析
webservice:就是应用程序之间跨语言的调用 1.xml:通过xml格式说明调用的地址方法如何调用 2.wsdl: webservice description language web服务描述语言 3.soap simple object access protoacl (简单对象访问协议)       客户端调用WebService的方式: 1.通过wximport生成代码
四种方式调用webservice
这个主要是用weblogic的workshop开发,用weblogic开发webservice具体可见沈辉的《Web Services开发教程.doc》,这里 主要是讲客户端调用,所以服务端只作罗列
Webservice客户端调用方式
一、生成ws client代码调用 该种方式使用简单,但一些关键的元素在代码生成时写死到生成代码中,不方便维护,所以仅用于测试。 二、service编程调用 该种方式可以自定义关键元素,方便以后维护,是一种标准的开发方式 import java.io.IOException; import java.net.MalformedURLException; import java.ne...
WebService调用的几种方式
WebService调用的几种方式,总结了Axis,Cxf,HttpClient,Myeclipse反向生成,XFire调用方式。
Webservice的几种调用方式
第一种:客户端方式wsimport 【掌握】 案例:手机号码归属地查询WEB服务 案例:天气查询WEB服务 第二种:Service方式 【了解】 案例:天气查询WEB服务 第三种:HTTPURLConnection方式【代码自己发送http请求-掌握】 案例:手机号码归属地查询WEB服务 第四种:Ajax调用方式【不要求掌握,原理与第三种一样,只不过是用js写】 n种:IOS:AFN…… 一、第一...
调用webService的几种方式
调用WebService的几种方式
webservice的POST和GET请求调用
webservice的POST和GET请求调用 POST请求 1.发送请求 /** * 发送POST请求 * @param wsdl url地址 * @param xml 请求体参数 * @return * @throws Exception */ import java.io.BufferedReader; import java.io.DataOutputStream; import ja...
Java调用.NET WebService Header处理
用的JBuilder2005rnrn代理类已经生成好了。。。rnrn用的Stub类进行的调用。。rnrn目前Header头处理方面出了问题,Header头对象确实发送过去了。。但是.NET的WebService方的Header头对象里UserName和PassWord标签字段没有值,都是Null...rnrn代码如下:rnrnorg.apache.axis.message.SOAPHeaderElement oHeaderElement = new org.apache.axis.message.SOAPHeaderElement(new QName("http://iata.cc/", "AuthHeader"));rnrnoHeaderElement.setPrefix("");rnoHeaderElement.setMustUnderstand(false);rnrnjavax.xml.soap.SOAPElement oElement = oHeaderElement.addChildElement("username");rnrnoElement.setPrefix("");rnoElement.addTextNode("APF3%G%^9GHK");rn rnoElement = oHeaderElement.addChildElement("password");rnoElement.setPrefix("");rnoElement.addTextNode("GW79%@!G@!(0");rnrntds.setHeader(oHeaderElement); //tds对象为JBuilder2005自动生成的WebServices代理类中的XXXXXXXXStub类。。 rnrnrn自动生成的代理类里对应WebService的Header类有两个。。 代码如下rn/**rn * AuthHeader.javarn *rn * This file was auto-generated from WSDLrn * by the Apache Axis 1.2beta3 Aug 01, 2004 (05:59:22 PDT) WSDL2Java emitter.rn */rnrnpackage cc.iata;rnrnpublic class AuthHeader implements java.io.Serializable rn private java.lang.String username;rn private java.lang.String password;rnrn public AuthHeader() rn rnrn public AuthHeader(rn java.lang.String username,rn java.lang.String password) rn this.username = username;rn this.password = password;rn rnrnrn /**rn * Gets the username value for this AuthHeader.rn *rn * @return usernamern */rn public java.lang.String getUsername() rn return username;rn rnrnrn /**rn * Sets the username value for this AuthHeader.rn *rn * @param usernamern */rn public void setUsername(java.lang.String username) rn this.username = username;rn rnrnrn /**rn * Gets the password value for this AuthHeader.rn *rn * @return passwordrn */rn public java.lang.String getPassword() rn return password;rn rnrnrn /**rn * Sets the password value for this AuthHeader.rn *rn * @param passwordrn */rn public void setPassword(java.lang.String password) rn this.password = password;rn rnrn private java.lang.Object __equalsCalc = null;rn public synchronized boolean equals(java.lang.Object obj) rn if (!(obj instanceof AuthHeader)) return false;rn AuthHeader other = (AuthHeader) obj;rn if (obj == null) return false;rn if (this == obj) return true;rn if (__equalsCalc != null) rn return (__equalsCalc == obj);rn rn __equalsCalc = obj;rn boolean _equals;rn _equals = true &&rn ((this.username==null && other.getUsername()==null) ||rn (this.username!=null &&rn this.username.equals(other.getUsername()))) &&rn ((this.password==null && other.getPassword()==null) ||rn (this.password!=null &&rn this.password.equals(other.getPassword())));rn __equalsCalc = null;rn return _equals;rn rnrn private boolean __hashCodeCalc = false;rn public synchronized int hashCode() rn if (__hashCodeCalc) rn return 0;rn rn __hashCodeCalc = true;rn int _hashCode = 1;rn if (getUsername() != null) rn _hashCode += getUsername().hashCode();rn rn if (getPassword() != null) rn _hashCode += getPassword().hashCode();rn rn __hashCodeCalc = false;rn return _hashCode;rn rnrnrnrnrnrnrn/////////////////////////////////////////////////////////////rn/**rn * AuthHeader_Helper.javarn *rn * This file was auto-generated from WSDLrn * by the Apache Axis 1.2beta3 Aug 01, 2004 (05:59:22 PDT) WSDL2Java emitter.rn */rnrnpackage cc.iata;rnrnpublic class AuthHeader_Helper rn // Type metadatarn private static org.apache.axis.description.TypeDesc typeDesc =rn new org.apache.axis.description.TypeDesc(AuthHeader.class, true);rnrn static rn typeDesc.setXmlType(new javax.xml.namespace.QName("http://iata.cc/", "AuthHeader"));rn org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();rn elemField.setFieldName("username");rn elemField.setXmlName(new javax.xml.namespace.QName("http://iata.cc/", "Username"));rn elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));rn elemField.setMinOccurs(0);rn typeDesc.addFieldDesc(elemField);rn elemField = new org.apache.axis.description.ElementDesc();rn elemField.setFieldName("password");rn elemField.setXmlName(new javax.xml.namespace.QName("http://iata.cc/", "Password"));rn elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));rn elemField.setMinOccurs(0);rn typeDesc.addFieldDesc(elemField);rn rnrn /**rn * Return type metadata objectrn */rn public static org.apache.axis.description.TypeDesc getTypeDesc() rn return typeDesc;rn rnrn /**rn * Get Custom Serializerrn */rn public static org.apache.axis.encoding.Serializer getSerializer(rn java.lang.String mechType,rn java.lang.Class _javaType,rn javax.xml.namespace.QName _xmlType) rn returnrn new org.apache.axis.encoding.ser.BeanSerializer(rn _javaType, _xmlType, typeDesc);rn rnrn /**rn * Get Custom Deserializerrn */rn public static org.apache.axis.encoding.Deserializer getDeserializer(rn java.lang.String mechType,rn java.lang.Class _javaType,rn javax.xml.namespace.QName _xmlType) rn returnrn new org.apache.axis.encoding.ser.BeanDeserializer(rn _javaType, _xmlType, typeDesc);rn rnrnrnrnrnrnAuthHeader_Helper类的org.apache.axis.description.TypeDesc和org.apache.axis.message.SOAPHeaderElement对象八杆子打不着一块去哎。。。rnrn请教AuthHeader_Helper如何使用。。。帮忙解决下Java如何发送Header信息到.Net的WebServices.....rn感激不尽。。。rnrnrnrn
相关热词 c# login 居中 c# 考试软件 c# 自然语言分析 c# 分段读取文件 c# 泛型反射 c#打断点 c# 时间转多少秒 c# 线程函数加参数 c# modbus 读取 c#查询集合表