How to: Expose the proxy generated from WCF LOB Adapter as a WCF Service hosted in IIS
Once your adapter is built and you want to host this adapter in IIS. The adapter can support let’s say 100 operations. You want to publish a service with 10 operations. To accomplish this you will use the Add Adapter Service Reference Visual Studio Plug-In to generate the proxy with 10 operations. Here are the steps to follow after you have the proxy -
1) Explore metadata from adapter (let’s say adapter support 100 operations) and generate a client proxy (with 10 operations) with app.config. The app.config contains a <binding> configuration section along with <client><endpoint>.
2) Create a new WCF Service project. File > New > Web Site > WCF Service
3) Copy the client proxy file into the WCF Service (rename to Service.cs) and use the class within this proxy as a ‘Code Behind’ in Service.svc
4) Update Web.Config with the content of <system.ServiceModel> from app.config.
5) Update Web.Config to create the right <service><endpoint>. For address, use the address where you want IIS to listen on. For contract, use the contract name generated in the proxy file. For binding, use either the WsHttpBinding or BasicHttpBinding. Ensure the name of the service is the class name in proxy file.
6) Build the project
7) Publish the service and host it in IIS.
8) If you used BasicHttpBinding, you can even use “Add Web Reference” to generate a client proxy. This client proxy can then be used in the BDC configuration file. The WCF LOB Adapter doesn’t generate the BDC configuration file, so it’s a manual effort to create it.
Here are some sample files:
Sample Web.Config
<system.serviceModel>
<client>
<endpoint
address="sap://LANG=en;@a/MSTC0147ENT/00"
binding="sapBinding"
bindingConfiguration="SAPBinding"
contract="Rfc"
name="SAPBinding_Rfc" />
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="MyServiceBehavior" name="RfcClient">
<endpoint
address=""
behaviorConfiguration="officeEndpointBehavior"
binding="basicHttpBinding"
bindingConfiguration="MyBasicHttpBinding"
name="bdcEndPoint"
contract="Rfc" />
<endpoint
address="secure"
behaviorConfiguration="officeEndpointBehavior"
binding="wsHttpBinding"
bindingConfiguration="MyWsHttpBinding"
name="wcfClientEndPoint"
contract="Rfc" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MyWsHttpBinding" bypassProxyOnLocal="true">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="MyBasicHttpBinding" bypassProxyOnLocal="true">
</binding>
</basicHttpBinding>
<sapBinding>
<binding name="SAPBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" rfcMetadataRetrievalMethod="Sdk"
receiveIdocFormat="Typed" generateFlatFileCompatibleIdocSchema="true"
rfcSdkTrace="false" maxConnectionsPerSystem="100" enableConnectionPooling="true"
idleConnectionTimeout="00:15:00" flatFileSegmentIndicator="SegmentDefinition"
enablePerfCounters="false" abapDebug="false" useSapGui="Without"
enableBiztalkLayeredChannel="false" />
</sapBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="officeEndpointBehavior">
<LobAuthBehaviorExtension UserNameHeader="UserPasswordHeaderValue"
PasswordHeader="PassWordHeaderValue" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Sample Service.svc
<% @ServiceHost Language=C# Debug="true" Service="RfcClient" CodeBehind="~/Service.cs" %>
Sample Generated Proxy à Service.cs
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "https://Microsoft.LobServices.Sap/2007/03/", ConfigurationName = "Rfc")]
public interface Rfc
{
// operation contract methods in it
}
public partial class RfcClient : System.ServiceModel.ClientBase<Rfc>, Rfc
{
// implementation of the methods
}
Comments
- Anonymous
July 11, 2007
An adapter built using WCF LOB Adapter SDK can be used in variety of topologies and scenarios. Follow