2016-06-03 3 views
2

내가 작성한 코드는 타사 웹 서비스와 통합하는 코드입니다. 문제는 테스트 및 프로덕션 환경에서 서비스 용 비누 동작이 다르며이 URI는 중요하지 않지만 호스트는 400을 반환합니다 - 비누 동작 URI가 잘못된 경우 잘못된 요청 오류가 발생합니다. 호스트 서비스는 Java로 작성됩니다. 우리는 C# 웹 서비스 프록시를 사용하고 있습니다.환경에 따라 비누 액션 URI 변경

Reference.cs 프로덕션 환경

/// <remarks/> 
     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://1.1.1.1:9080/wss/Ping", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)] 
     [return: System.Xml.Serialization.XmlElementAttribute("PingResp", Namespace="http://namespace/data")] 
     public PingResp Ping([System.Xml.Serialization.XmlElementAttribute("PingReq", Namespace="http://namespace/data")] PingReq PingReq) { 
      object[] results = this.Invoke("Ping", new object[] { 
         PingReq}); 
      return ((PingResp)(results[0])); 
     } 

,이 SOAPAction은 :

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://2.2.2.2:9080/wss/Ping", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)] 

즉이 동적으로 만들 수있는 방법이이 구성 설정에 기초 비누 동작 URI를 변경할 수는?

나는 SoapDocumentMethodAttribute 클래스를 확장하려고 시도했지만 봉인되어 있습니다.

답변

2

컴파일 타임 상수가 필요하므로 컴파일하기 전에이 값을 설정해야합니다. 따라서 환경을 기반으로하고 있기 때문에 ConfigurationManager과 같은 것을 사용할 수 없습니다.

#if 전처리기를 통해 채워지는 const 속성으로 전역 정적 클래스를 만들고 빌드 할 때 조건부 컴파일 기호를 지정할 수 있습니다.

public static class GlobalConstants 
    { 
#if DEBUG 
     public const string Uri = "devUri"; 
#endif 
#if TEST 
     public const string Uri = "testUri"; 
#endif 
#if RELEASE 
     public const string Uri = "releaseUri"; 
#endif 

    } 

그리고 당신은 새로운 환경으로 마이그레이션 할 때 복잡성을 추가 않습니다

[System.Web.Services.Protocols.SoapDocumentMethodAttribute(GlobalConstants.Uri, Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)] 

이처럼 사용할 수 있지만 그것은 당신이 찾고있는 무슨에 가까운 무언가를 얻을 수있는 방법이다.

빌드시 컴파일 기호 지정에 관한 일부 문서 : https://msdn.microsoft.com/en-us/library/0feaad6z.aspx

관련 문제