惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Know Your Adversary
Know Your Adversary
小众软件
小众软件
L
LangChain Blog
月光博客
月光博客
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
MongoDB | Blog
MongoDB | Blog
Recorded Future
Recorded Future
V
Visual Studio Blog
TaoSecurity Blog
TaoSecurity Blog
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
L
LINUX DO - 热门话题
C
Check Point Blog
F
Fortinet All Blogs
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
博客园 - 司徒正美
T
Threatpost
P
Palo Alto Networks Blog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
Engineering at Meta
Engineering at Meta
N
News | PayPal Newsroom
T
Tailwind CSS Blog
The Last Watchdog
The Last Watchdog
Blog — PlanetScale
Blog — PlanetScale
A
Arctic Wolf
量子位
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Google Online Security Blog
Google Online Security Blog
Google DeepMind News
Google DeepMind News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Vulnerabilities – Threatpost
H
Hacker News: Front Page

博客园 - nect

【转】ie9 rc版软件兼容问题 [z]前端设计IE6/IE7/IE8/IE9/FF问题汇总:IE和FirFox兼容问题 - nect - 博客园 [z]ie和FF 在insertRow和insertCell的区别 [z]JS在IE和FF下attachEvent,addEventListener学习笔记 - nect - 博客园 WinForm使用webclient通过http的POST方式上传文件 转:另类解决:“ScriptManager”不是已知元素。原因可能是网站中存在编译错误。 - nect - 博客园 转:css妙用1-用图片替换文字 .net中的正则表达式(一)——转义字符 使用Cascadingdropdown控件遇到的一个问题 IP地址匹配算法 服务器控件的客户端验证脚本 从一个字符串中Remove另一个字符串 gridview 中模板列无法响应row_command事件 - nect - 博客园 在asp.net Atlas中调用 Web Service时无法找到自定义的Web Service对象的可能原因 【转】Prototype.js开发笔记//mark一下 在GridView中使用邮件链接 【转】ASP.net2。0中解决无法获取 GridView 隐藏列值问题 GridView 中格式化整理 [转]操纵自如--页面内的配合与通信
[导入]Java调用.net的WebService
nect · 2007-08-16 · via 博客园 - nect

这几天公司需要做一个java和.net项目的整合,其中.net做了一个WebService,需要java来调用。本以为很容易的一个东西,结果弄了几天才弄好。

最开始.net的Service代码如下(黄色背景是自己增加的代码):

//<%@ WebService Language="C#" Class="Service" Debug=true %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace Service
{
 [WebService(Namespace="http://192.168.168.180/ss/Service.asmx")]

 /// <summary>
 /// Service1 的摘要说明。
 /// </summary>
 public class Service : System.Web.Services.WebService
 {
  public Service()
  {
   //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的
   InitializeComponent();
  }

  #region 组件设计器生成的代码
  
  //Web 服务设计器所必需的
  private IContainer components = null;
    
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {

  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if(disposing && components != null)
   {
    components.Dispose();
   }
   base.Dispose(disposing);  
  }
  
  #endregion

  [WebMethod(Description="test")]
  public string GetTestQuestions(string TeacherName,string Subject)
  {
   return "11111";
  }

 }
}
=================

Java调用代码:

 public static String GetTestQuestions(String TeacherName,String Subject){
  String result = "";
  try{
   Service service = new Service();
   Call call = (Call) service.createCall();
   call.setOperationName(new QName("", "GetTestQuestions"));
   call.addParameter("TeacherName", XMLType.XSD_STRING, ParameterMode.IN);
   call.addParameter("Subject", XMLType.XSD_STRING, ParameterMode.IN);
   call.setTargetEndpointAddress(new URL(
       "http://192.168.168.180/ss/Service.asmx"));    
   result  = (String) call.invoke(new Object[] { TeacherName, Subject});   
   
  }catch(Exception e){
   e.printStackTrace();
  }
  
  return result;
 }
 public static void main(String args[]){
  System.out.println(UserWebService.GetTestQuestions("aaa", "HOMA060E"));

 }
--------------------

结果用java调用时总提示:faultString: 服务器未能识别 HTTP 标头 SOAPAction 的值:。
--------------------

上网找了解决方法,最好修改的结果如下:

.net WebService代码:

在webservicenamespace后面增加:

[SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)]

java调用错误变成了:faultString: 无法识别请求元素 &lt;GetTestQuestions xmlns=''&gt;。

崩溃了……

……

经过做java同学的不懈努力,终于找到解决方法:

java绿色背景代码更改成:

call.setOperationName(new QName("http://192.168.168.180/ss/Service.asmx", "GetTestQuestions"));
终于得到期待的结果了。

总结一下原因:

.net的webservice指定了namespace:http://192.168.168.180/ss/Service.asmx,但是java调用时没有指定,所以总提示找不到“<GetTestQuestions xmlns=''>”,如果我们仔细查看.net webservice的soap请求格式时会发现,要求的格式是(注意蓝色背景的文字)

SOAP

下面是一个 SOAP 请求和响应示例。所显示的占位符需要由实际值替换。

POST /ss/service.asmx HTTP/1.1
Host: 
192.168.168.180
Content
-Type: text/xml; charset=utf-8
Content
-Length: length
SOAPAction: 
"http://192.168.168.180/ss/Service.asmx/GetTestQuestions"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    
<GetTestQuestions xmlns="http://192.168.168.180/ss/Service.asmx">
      <TeacherName>string</TeacherName>
      
<Subject>string</Subject>
    
</GetTestQuestions>
  
</soap:Body>
</soap:Envelope>

文章来源:http://nect.blog.163.com/blog/static/11633941200771695410692