How can I set message encoding for a web reference - vb.net

I've been given a service which I need to consume. This service is only happy when added to the project as a 'web reference' and NOT a 'service reference'. When I add the reference, the app.config is modified as shown here...
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="TestApp.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<TestApp.My.MySettings>
<setting name="TestApp_DemoService_Rfx" serializeAs="String">
<value>https://www.mydemosourcesite.com:443/common/services/Rfx/</value>
</setting>
</TestApp.My.MySettings>
</applicationSettings>
I can consume the service fine, except that the response it's returning uses MTOM. My question is - how can I configure this service to use MTOM for the message encoding. If I were doing this with a service reference, I'd do this...
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="RfxSOAP" messageEncoding="Mtom">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://www.mydemosourcesite.com:443/common/services/Rfx/" binding="basicHttpBinding" bindingConfiguration="RfxSOAP" contract="DemoService.Rfx" name="RfxSOAP" />
</client>
</system.serviceModel>
Sadly though, I'm not using a service reference and no idea how to get this configured for a web reference! This is in VB and .NET 4.
All help appreciated!

Related

How to Enable GZip Compression when Communicating with a Remote Service Using WSDL and WCF

I'm trying to send data to the IRS using a WSDL file and WCF. I'm using .NET and Microsoft VS.NET, which created a proxy class I'm utilizing to communicate.
My problem is I keep getting a message saying GZip compression is required from the IRS:
The request message must be sent using HTTP compression (RFC 1952 - GZIP). Please review the transmission instructions outlined in Section 5 of Publication 5258, AIR Submission Composition and Reference Guide, located at https://www.irs.gov/e-file-providers/air/affordable-care-act-information-return-air-program, correct any issues, and try again.'
The publication referred to in the error message is very generic and is not specific to .NET and WCF. I did some research and found a way to enable GZip compression in web.config:
<binaryMessageEncoding compressionFormat="GZip" />
However, I now get this error:
The content type text/xml;charset=utf-8 of the response message does not match the content type of the binding (application/soap+msbin1+gzip). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly.
Does anyone know what I'm doing wrong? Do I need to create a custom encoder? Here's is my full web.config file:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2"/>
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GetACATransmitterStatusReqBinding">
<security mode="Transport" />
</binding>
<binding name="GetACATransmitterStatusReqBinding1" />
</basicHttpBinding>
<customBinding>
<binding name="BulkRequestTransmitterBinding">
<!--<textMessageEncoding messageVersion="Soap11WSAddressing10" />-->
<binaryMessageEncoding compressionFormat="GZip" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://la.www4.irs.gov/airp/aca/a2a/1095BC_Transmission_AATS"
binding="customBinding" bindingConfiguration="BulkRequestTransmitterBinding"
contract="BulkRequestTransmitterService.BulkRequestTransmitterPortType"
name="BulkRequestTransmitterPort" />
<endpoint address="https://la.www4.irs.gov/airp/aca/a2a/1095BC_Status_Request_AATS"
binding="basicHttpBinding" bindingConfiguration="GetACATransmitterStatusReqBinding"
contract="ACAGetTransmitterBulkRequestStatus.ACATransmitterStatusReqPortType"
name="ACATransmitterStatusReqPort" />
</client>
</system.serviceModel>
</configuration>

Capture WCF client request with a proxy configuration

I need to capture trafic with fiddler but in my config i need to specify a proxy to perform the connection my .config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="asdClientTest.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy proxyaddress="http://zzzzz"></proxy>
</defaultProxy>
</system.net>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ATEX">
<security mode="Transport" />
</binding>
<binding name="ATEX1">
<security mode="Transport" />
</binding>
<binding name="ATEX2" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://zzzzzzzz"
binding="basicHttpBinding" bindingConfiguration="ATEX" contract="WS.ConsultaATEX"
name="ATEX" />
</client>
</system.serviceModel>
</configuration>
but fiddler is not capturing nothing.
does anyone help me?
I believe here you will find how to properly configure Fiddler to achieve what you need.
If your server is running locally you may be missing bypassonlocal="False" in the <proxy> tag. I took this information from here.
Hope it helps!

SOAP Create web-server for IIS with BizTalk

I have to configurate SOAP web-service with BizTalk involving
How it must works
1. Client has login/pass going to https://soap.mjr.ru/soap.svc
2. Client send Request like
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:doc="https://docflow.mjr.ru.Request">
<soapenv:Header/>
<soapenv:Body>
<doc:Request>
<MessageIdentifier>1231</MessageIdentifier>
<MessageType>3B18</MessageType>
<MessagePriority>1</MessagePriority>
<XmlRequest>kuehgiuehriveiveibveifbveifbviebfvieb</XmlRequest>
<Sender>123456789</Sender>
<Receiver>123456789</Receiver>
</doc:Request>
</soapenv:Body>
</soapenv:Envelope>
SOAP server at my side receive request and send back to Client answer about good receipt or error code
Server take from inbound message data from Request field and put it like XML into folder
What i have done
In Visual Studio I Have created new BT project with XSD for Request and Response
I have deployed this project into BTS
Within utilite BizTalk WCF service Publishing Wizard I have publicate schemas as service into /soap/soap.svc
Configurate subsite Application Spool by SQL user for DB connection
Create new site in IIS and bind it for https://soap.mjr.ru
Configurate permission for client user for this folder
In BizTalk Server Administrator configurate Receive Port & Receive Location (they have been created automatically). Rewrite address to file from /soap/soap.svc to `/soap.svc'
Run application in BTS and after i can see the file at https://soap.mjr.ru/soap.svc?WSDL
But i can't reach my service with SOAPUI. Here i have 401 error.. and that's all
Please help with correct configuration
listing of web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="bizTalkSettings" type="Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkConfigurationSection,
Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</configSections>
<bizTalkSettings>
<mexServiceHostFactory debug="false">
<receiveLocationMappings>
</receiveLocationMappings>
</mexServiceHostFactory>
<webServiceHostFactory debug="false" />
<isolatedReceiver disable="false" />
<btsWsdlExporter disable="false" />
</bizTalkSettings>
<appSettings />
<connectionStrings />
<system.web>
<customErrors mode="Off" />
<compilation defaultLanguage="c#" debug="false">
<assemblies>
<add assembly="mscorlib, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" />
<add assembly="Microsoft.BizTalk.Adapter.Wcf.Common, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add assembly="Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</assemblies>
</compilation>
<authentication mode="Windows" />
<identity impersonate="false" />
</system.web>
<system.serviceModel>
<extensions><behaviorExtensions><add name="btsWsdlExporter" type="Microsoft.BizTalk.Adapter.Wcf.Metadata.BtsWsdlExporterElement,
Microsoft.BizTalk.Adapter.Wcf.Runtime, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /></behaviorExtensions></extensions>
<bindings>
<basicHttpBinding>
<binding name="httpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<diagnostics>
<endToEndTracing activityTracing="true" messageFlowTracing="true" propagateActivity="true">
</endToEndTracing>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviorConfiguration">
<serviceDebug httpHelpPageEnabled="true" httpsHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkServiceInstance" behaviorConfiguration="ServiceBehaviorConfiguration">
<host>
<baseAddresses>
<add baseAddress="https://10.8.1.226/soap.svc" />
<add baseAddress="https://soap.mjr.ru/soap.svc" />
</baseAddresses>
</host>
<endpoint name="HttpMexEndpoint" address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>

Why does this WCF call fail when passing in a federated security token

I'm trying to pass a security token from a client application into a WCF service for authentication.
For this example I'm just using the standard File, New WCF Application project and trying to call the GetData method.
I get the following exception on the client
{"The message could not be processed. This is most likely because the
action 'http://tempuri.org/IService1/GetData' is incorrect or because
the message contains an invalid or expired security context token or
because there is a mismatch between bindings. The security context
token would be invalid if the service aborted the channel due to
inactivity. To prevent the service from aborting idle sessions
prematurely increase the Receive timeout on the service endpoint's
binding."}
If I enable tracing on the WCF service I can see the following error
There was no channel that could accept the message with action
'http://tempuri.org/IService1/GetData'.
The Web.Config for my service looks like this
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<!--Configure STS-->
<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="https://stsserver.security.int/myApp" />
</audienceUris>
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089">
<trustedIssuers>
<add thumbprint="‎3c8fc34bd483b07ba0d1509827fc4788c36247e4" name="StartSSL Login" />
</trustedIssuers>
</issuerNameRegistry>
<certificateValidation certificateValidationMode="None"/>
</identityConfiguration>
</system.identityModel>
<system.serviceModel>
<bindings>
<ws2007FederationHttpBinding>
<binding name ="IdentityServer">
<security mode="TransportWithMessageCredential">
</security>
</binding>
</ws2007FederationHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="Services.Service1" behaviorConfiguration="CertificateBehavior">
<endpoint name="ws" binding="ws2007FederationHttpBinding" bindingConfiguration="IdentityServer" contract="Services.IService1" address=""/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CertificateBehavior">
<serviceCredentials>
<serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
The method in my client application that calls this WCF service looks like this
static void CallSecuredService(SecurityToken samlToken)
{
var binding = new WS2007FederationHttpBinding((WSFederationHttpSecurityMode.TransportWithMessageCredential));
binding.Security.Message.IssuedKeyType = SecurityKeyType.BearerKey;
binding.Security.Message.EstablishSecurityContext = false;
var factory = new ChannelFactory<IService1>(binding, new EndpointAddress("https://localhost/myservice/Service1.svc"));
factory.Credentials.SupportInteractive = false;
factory.Credentials.UseIdentityConfiguration = true;
var proxy = factory.CreateChannelWithIssuedToken(samlToken);
Console.WriteLine(proxy.GetData(1));
}
Any pointers as to things I should check would be great as I'm at a bit of a loss with this one now. I'm not sure how I can debug this any further?
I finally managed to get past this error. The problem was a small miss match between the service and client bindings.
Changing my bindings in the web.config to this fixed the issue
<bindings>
<ws2007FederationHttpBinding>
<binding name ="IdentityServer">
<security mode="TransportWithMessageCredential">
<message issuedKeyType="BearerKey" establishSecurityContext="false"/>
</security>
</binding>
</ws2007FederationHttpBinding>
</bindings>

How to give endpoint address in standardendpoint element tag in wcf?

in my local machine services are running fine.but while placing published files to other system then services are not running.please tell me.my web.config file is below.please tell me where to give endpoint addresses.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
<connectionStrings>
<add name="TestDataEntities" connectionString="metadata=res://*/AMI.csdl|res://*/AMI.ssdl|res://*/AMI.msl;provider=System.Data.SqlClient;provider connection string="Data Source=Venkat-PC;Initial Catalog=TestData;User ID=sa;Password=p#ssw0rd;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
You cannot define endpoint address for standard endpoint. Standard endpoint is just a template applied on the real endpoint. The real endpoint in your case should be defined by your hosted web application (url of your application) and routes defined in your Global.asax (relative part of your url).