locked
Help Needed in appsettings RRS feed

  • Question

  • User1489758560 posted

    Hi, 

    I am working in asp.net core .2.2 and i am trying  to call the third party SOAP service. i have a working sample with .net framework. trying to make it work with core API.

    here is my try,

    created a core class library and added the service reference using "Connected Services" feature. then i added the dll in core API. now i wnated to conver the below webconfig code to Appsettings.json 

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="xxx.az">
              <clientCredentials>
                <clientCertificate findValue="www.xxx.com"  storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
                <serviceCertificate>
                  <defaultCertificate  findValue="services.xxx.com" storeLocation="LocalMachine" storeName="My"  x509FindType="FindBySubjectName" />
                </serviceCertificate>
              </clientCredentials>
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <bindings>
          <!--<customBinding>
            <binding name="TestSoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"  sendTimeout="00:01:00">
              <textMessageEncoding messageVersion="Soap12" />
              <httpTransport />
            </binding>
          </customBinding>-->
    
          <customBinding>
            <binding name="TestSoapBinding">
              <textMessageEncoding messageVersion="Soap12" />
    
              <security  defaultAlgorithmSuite="Basic128Rsa15" allowSerializedSigningTokenOnReply="true" authenticationMode="MutualCertificate"
                   securityHeaderLayout="Lax" messageProtectionOrder="SignBeforeEncrypt"
                         messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
                         requireSecurityContextCancellation="false">
              </security>
              <httpsTransport manualAddressing="false" maxBufferPoolSize="524288"
                            maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                            keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                            useDefaultWebProxy="true" />
            </binding>
          </customBinding>
        </bindings>
        <client>
          <endpoint address="https://xxx.services.com/GetInfo"
              binding="customBinding" bindingConfiguration="TestSoapBinding"
              contract="TestService" name="TestServiceTestPort" behaviorConfiguration="xxx.az" />
        </client>
      </system.serviceModel>
    </configuration>

    would it be possible to have these setting in appsettigngs.json file? then how can i add this in statup.cs? any help would be highly appreciated.

    Tuesday, November 19, 2019 9:55 PM

All replies

  • User475983607 posted

    born2win

    would it be possible to have these setting in appsettigngs.json file? then how can i add this in statup.cs?

    Not without a little work.  You'll need to write code to set the addresses and bindings.  I create a service reference to get the object model.  Then I modify the generated code to fit my needs.  The generated code will have GetBindingForEndpoint() and GetEndpointAddress() methods.  It has basic a custom bindings by default but I write code to configure the bindings.   You can use the app.config XML you posted above as a template.

    It's pretty easy to move the configurable bits to configuration but you'll need to read the ASP.NET docs on configuration which is a separate issue.

    Tuesday, November 19, 2019 10:12 PM