title: Generate a WCF client proxy for a netstandard Xamarin.Forms project
body: <p>I've created a Xamarin.Forms project with a <code>netstandard2.0</code> targeting library instead of a shared or PCL library. So far this compiles and works. I'm using an up2date version of Visual Studio 2017 Community.</p>
  
  <p>I also have created a WCF service that gonna be hosted on windows itself (not IIS). I've configured my app.config to provide a Metadata Exchange Endpoint:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
      &lt;startup&gt;
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;
      &lt;/startup&gt;
      &lt;system.serviceModel&gt;
          &lt;services&gt;
              &lt;service behaviorConfiguration="MM.Server.ServiceServerBehavior" name="MM.Server.ServiceServer"&gt;
                  &lt;endpoint address="net.tcp://localhost:8730/MMServer/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IServiceServer" bindingName="NetTcpBinding_IServiceServer_EndPoint" contract="MM.Contracts.IServiceServer"&gt;
                      &lt;identity&gt;
                          &lt;dns value="localhost"/&gt;
                      &lt;/identity&gt;
                  &lt;/endpoint&gt;
                  &lt;endpoint address="http://localhost:8731/MMServer/mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
                  &lt;host&gt;
                      &lt;baseAddresses&gt;
                          &lt;add baseAddress="net.tcp://localhost:8730/MMServer/"/&gt;
                      &lt;/baseAddresses&gt;
                  &lt;/host&gt;
              &lt;/service&gt;
          &lt;/services&gt;
          &lt;behaviors&gt;
              &lt;serviceBehaviors&gt;
                  &lt;behavior name="MM.Server.ServiceServerBehavior"&gt;
                      &lt;serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8731/MMServer/mex" /&gt;
                      &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
                  &lt;/behavior&gt;
              &lt;/serviceBehaviors&gt;
          &lt;/behaviors&gt;
          &lt;bindings&gt;
              &lt;netTcpBinding&gt;
                  &lt;binding name="NetTcpBinding_IServiceServer" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="10" maxReceivedMessageSize="2147483647"&gt;
                      &lt;readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/&gt;
                      &lt;reliableSession ordered="true" inactivityTimeout="01:00:00" enabled="false"/&gt;
                      &lt;security mode="None"&gt;&lt;!-- TODO: Add more security later --&gt;
                          &lt;transport clientCredentialType="None" protectionLevel="None"/&gt;
                      &lt;/security&gt;
                  &lt;/binding&gt;
              &lt;/netTcpBinding&gt;
          &lt;/bindings&gt;
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>This is a very simple configuration and I don't care about security for now. The service runs, successfully.</p>
  
  <p>Now I cannot simply add a service reference to my Xamarin.Forms project, since <code>netstandard</code> does not provide <code>System.ServiceModel</code>. </p>
  
  <p>I've found out that <a href="https://github.com/sami1971/SimplyMobile/wiki/Step-by-step-WCF-client-creation-for-iOS-&amp;-Android" rel="noreferrer">I can use the SLsvcUtil.exe</a> from the Silverlight SDK to generate the client proxy for my WCF service that is compatible to Xamarin.Forms targeting <code>netstandard</code> instead, however I cannot get it running. </p>
  
  <p>No matter how I try to use the SLsvcUtil.exe while my WCF service is running, I always get the error:</p>
  
  <pre><code>Error: An error occurred in the tool.
  Error: Object reference not set to an instance of an object.
  </code></pre>
  
  <p>Here is my batch that I used to execute SLsvcUtil.exe:</p>
  
  <pre><code>set "namespace=*,MM.Services"
  set "mexPath=http://localhost:8731/MM/mex"
  set "svcutil=C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Tools\SLsvcUtil.exe"
  set "outputDir=C:\vsproj\Xamarin\MM\MM.App"
  "%svcutil%" %mexPath% /directory:"%outputDir%" /namespace:"%namespace%"
  pause
  </code></pre>
  
  <p><a href="http://localhost:8731/MM/mex" rel="noreferrer">http://localhost:8731/MM/mex</a> returns the full WSDL, successfully.</p>
  
  <p>How can I get a working generated client proxy for my Xamarin.Forms app that is targeting <code>netstandard2.0</code>? I'm open for any alternative that leads to the same desired result.</p>