【问题标题】:Write .net web service consumes from SAP从 SAP 写入 .net Web 服务使用
【发布时间】:2012-12-14 02:36:36
【问题描述】:

我需要编写 .Net (C#) 一个从 SAP 端使用的 Web 服务。我编写了 c# 网络服务,但问题是需要添加 HTTP 请求标头。实际上我不知道如何将 HTTP 请求标头添加到 Web 服务?我添加了 SOAP Header 但 SAP 端需要 HTTP 请求 Header。

示例代码

    public class TestService : System.Web.Services.WebService
    {
         public class AuthSoapHeader : SoapHeader
         {
              public AuthSoapHeader() { }

              public string Username = string.Empty;
              public string Password = string.Empty;
         }

        [WebMethod]
        [SoapHeader("AuthHeader")]
        public List<Response> Testmethod(TestClass testData)
        {

            if ( AuthHeader.Username == "testuser" && AuthHeader.Password == "testpawd")
            {
            }
        }
    }

请问有人知道怎么做吗?

谢谢

【问题讨论】:

  • 如果您向我们展示您的代码,我们可能会为您提供帮助,但如果不知道您做了什么,很难发表评论。
  • @Mike Parkhill 我添加了示例代码

标签: c# .net web-services sap


【解决方案1】:

我已经研究过类似的解决方案,但在 VB.net 中。在那个解决方案上,我创建了一个单独的层(项目)来处理 SAP 通信和数据检索。 下面的代码是带有 SOAP 身份验证的 webservice sn-p。

<SoapHeader("Authentication", Required:=True)> _
<WebMethod(Description:="SAP search")> _
Public Function SampleSearch() As String

    Dim objSearch As New clsSapSearch
    Dim dsReturn As New DataSet
    dsReturn.Tables.Add(objSearch.Search("parameter1", "parameter2"))

    Return GetXmlIncludingNull(dsReturn)

End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 2011-04-09
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多