java wsdl asmx 替换_WebService asmx生成的wsdl 修改 location
大家好,又见面了,我是你们的朋友全栈君。
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);
}
}
}
}
}
}
}
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/139642.html原文链接:https://javaforall.cn
相关文章
- JAVA多线程面试题_java多线程的实现方式
- java局域网发送文件_Java如何实现局域网文件传输代码案例分享
- fileinputstream java,使用url的Java fileinputstream
- fileinputstream java_Java FileInputStream close()方法
- java卸载 安装错误_Java卸载后无法重新安装 提示已安装过[通俗易懂]
- java 删除目录下所有文件_Java删除文件、目录及目录下所有文件的方法实例
- java python哪个好_java和python哪个更好用?(一)[通俗易懂]
- java pfx 证书_Java将pfx证书转换为jks[通俗易懂]
- 说一下java的运行机制_Java运行机制是什么?「建议收藏」
- MySQL字段类型如何转为java_Java JDBC中,MySQL字段类型到JAVA类型的转换
- java加入md5_javamd5加密解密
- Java Session获取/销毁
- java基本数据类型 think in java_Think in Java(一):Java基础[通俗易懂]
- JAVA的使用_Java集成开发环境
- initialj — 我的第一个Java项目开发脚手架
- Java生成随机数组_java生成唯一数字
- java在线生成uuid_Java生成uuid
- 反编译Java_java反编译的代码可以修改么
- Java-String类&集合ArrayList
- Java使用iText生成PDF文件详解编程语言
- Java并发编程之volatile详解编程语言
- 利用Redis存储Java对象的方法(redis存储java对象)
- Java应用中Redis数据过期清理策略(redisjava过期)
- 操作Redis Java中自动处理过期数据(redisjava过期)
- 处理Java实现Redis中Key的过期处理(redisjava过期)
- 使用Java实现Redis数据存储(redis集成java)
- Java实现Redis数据存储(java的redis)
- java中通用的线程池实例代码
- Java生成随机数的2种示例方法代码