java wsdl asmx 替换_WebService asmx生成的wsdl 修改 location

java wsdl asmx 替换_WebService asmx生成的wsdl 修改 locationC#中使用webservice接口的时候,返给服务器的IP地址是带上了端口号的。但是有时候不能要那个端口(比如用nginx做了转发),就需要在服务端处理一下(处理内容就是后面的代码)。此外,需要在配置文件中web.config中的system.web中添加一些东西:2.如果没有protocols中的内容的话,有可能post和get请求不能被正确识别(未做过验证,只是在博客园上看见过类似问题)。代码…

大家好,又见面了,我是你们的朋友全栈君。

C#中使用webservice接口的时候,返给服务器的IP地址是带上了端口号的。但是有时候不能要那个端口(比如用nginx做了转发),就需要在服务端处理一下(处理内容就是后面的代码)。此外,需要在配置文件中web.config中的system.web中添加一些东西:

2.如果没有protocols中的内容的话,有可能post和get请求不能被正确识别(未做过验证,只是在博客园上看见过类似问题)。

代码:

//———————————————————————–

//

// * Copyright (C)

// * version :

// * author  : ying83811

// * FileName: OuterPortReflector.cs

// * history : created by ying83811

//

//———————————————————————–

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web.Services.Description;

namespace Better517Na.KoreaProductInterface.CommMethod

{

///

/// OuterPortReflector类

///

public class OuterPortReflector : SoapExtensionReflector

{

///

/// 重写ReflectMethod

///

public override void ReflectMethod()

{

}

///

/// 重写ReflectDescription

///

public override void ReflectDescription()

{

//  为了说明问题,这里直接把端口号写死了,建议写在配置文件中

string portNum = “8888”;

portNum = “:” + portNum;

ServiceDescription description = ReflectionContext.ServiceDescription;

foreach (Service service in description.Services)

{

foreach (Port port in service.Ports)

{

foreach (ServiceDescriptionFormatExtension extension in port.Extensions)

{

SoapAddressBinding binding = extension as SoapAddressBinding;

if (null != binding)

{

binding.Location = binding.Location.Replace(portNum, string.Empty);

}

else

{

HttpAddressBinding httpBinding = extension as HttpAddressBinding;

if (httpBinding != null)

{

binding.Location = “https://baidu.com”;

httpBinding.Location = httpBinding.Location.Replace(portNum, string.Empty);

}

else

{

binding.Location = “https://baidu.com”;

Soap12AddressBinding soap12Binding = extension as Soap12AddressBinding;

if (soap12Binding != null)

{

soap12Binding.Location = soap12Binding.Location.Replace(portNum, string.Empty);

}

}

}

}

}

}

}

}

}

b3d46e7ddfcf9c7654d188d0187cca89.png

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/139642.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux修改文件内容【命令】

    Linux修改文件内容【命令】在/opt/hello/world.txt文件中增加一行 hellolinuxworld!方法一:命令是:vi,vimvi编辑器,相当于记事本,有编辑功能,但较弱vim复杂的编辑器,相当于windows的editplus,notepad++等————————步骤:1、执行viworld.txt 进入编辑器(默认

    2022年7月26日
  • python安装cv2模块的方法(python中cv2库)

    python如何安装cv2模块  大家在第一次安装cv2模块的时候可能会犯这样的错误,输入pip(3)installcv2命令后,vc2并没有开始安装,而是返回这样一个错误一个错误:Couldnotfindaversionthatsatisfiestherequirementcv2(fromversions:)Nomatchingdistributionf…

    2022年4月14日
  • Textmate使用手册「建议收藏」

    Textmate使用手册「建议收藏」Textmate使用手册cmd+option+L显示行号cmd+F页面搜索文字cmd+shift+F项目搜索文字cmd+G下一个搜索文字cmd+shift+G上一个搜索文字cmd+option+F替换一个cmd+ctrl+F全部替换cmd+S保存cmd+option+S全部保存

    2022年7月13日
  • 大数据脱敏

    大数据脱敏

    2021年11月27日
  • C# SqlTransaction的使用[通俗易懂]

    C# SqlTransaction的使用[通俗易懂]Sqltransaction是用在多sql任务写数据库时的Codeusing(SqlConnectionconn=newSqlConnection(SqlHelper.ConnectionString)){conn.Open();…

    2022年5月1日
  • git上项目代码拉到本地方法

    git上项目代码拉到本地方法1、先在本地打开workspace文件夹,或者自定义的文件夹,用来保存项目代码的地方。2、然后登陆GitHub账号,点击复制项目路径3、在刚才文件夹下空白处点击鼠标右键,打开Git窗口4、在以下页面中输入命令gitclone加刚才复制的路径,如下图(可能Ctrl+V用不了,可以用右键选择Paste完成复制)5、输入完命令行之后回车就行,等待下载完毕,然后是切换…

    2022年5月29日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号