如何为使用 Axis 1.4 Web 服务的 C# Web 服务客户端添加自定义 Http 标头 [英] How to add custom Http Header for C# Web Service Client consuming Axis 1.4 Web service

查看:39
本文介绍了如何为使用 Axis 1.4 Web 服务的 C# Web 服务客户端添加自定义 Http 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 C# 编写一个 Web 服务客户端,其中的 Web 服务是 Java Axis 1.4.Axis 服务需要 HTTP 标头中的 Authorization: Basic Base64EncodedToken 标头值.我找不到在 Visual Studio.net 中以标准方式使用 Web 服务来设置此标头的方法,例如普通 WSDL 生成的引用或 WSE3.0

I'm trying to write a web service client in c# which the webservice is Java Axis 1.4. Axis service requires the Authorization: Basic Base64EncodedToken header value in the HTTP Headers. I can't find a way to set this header in standart ways of consuming web services in visual studio.net, like normal WSDL generated refernce nor with WSE3.0

我无法使用 WCF,因为该项目是使用 .net 2.0 开发的.

I can't use WCF as the project is developed using .net 2.0.

有没有办法做到这一点?

Is there any way to do this ?

推荐答案

看来原作者已经找到了他们的解决方案,但是对于其他任何想要添加实际自定义标头的人,如果您有权访问生成的协议您可以覆盖 GetWebRequest 的代码:

It seems the original author has found their solution, but for anyone else who gets here looking to add actual custom headers, if you have access to mod the generated Protocol code you can override GetWebRequest:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
  System.Net.WebRequest request = base.GetWebRequest(uri);
  request.Headers.Add("myheader", "myheader_value");
  return request;
}

如果您想进入它,请确保删除 DebuggerStepThroughAttribute 属性.

Make sure you remove the DebuggerStepThroughAttribute attribute if you want to step into it.

这篇关于如何为使用 Axis 1.4 Web 服务的 C# Web 服务客户端添加自定义 Http 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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