Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Friday, March 31, 2017

How to configure a WCF service running like Rest Service?

I have various posts on the configure of WCF. i will show you another configure if you want your WCF service to call with rest service call like

http://WCFHostServer/myWCF.svc/YourMethod

Note to be taken:

1. must use the webHttpBinding.
2. enable HttpsGet in service behaviors setting
3. add <webHttp> to endpoint behavior setting.

here is WCF configuration in my sample wcf application

  <system.serviceModel>
    <services>
      <service name="MyWCF"
               behaviorConfiguration="MyWCF.Service1Behavior">
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="EndPointBehavior"
                  contract="MyWCF.IMyWCF"
                    bindingConfiguration="wbBind">
          </endpoint>
          </service>
        </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyWCF.Service1Behavior">
          <serviceMetadata httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <serviceCredentials>
            <windowsAuthentication allowAnonymousLogons="False" includeWindowsGroups="True"/>
          </serviceCredentials>
          </behavior>
        </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="EndPointBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="wbBind">
          <security mode="Transport">
            <transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
            </security>
            </binding>
          </webHttpBinding>
    </bindings>
  </system.serviceModel>

Wednesday, October 19, 2016

HTTP vs HTTPS binding in Dynamic AX WCF service configuration

We might think that it is quite easy to swtich from HTTP to HTTPS in the WCF Service binding configuration, as we just simply replace the HTTP in http:// WCFServiceServer/WCFServce.svc  to HTTPS https:// WCFServiceServer/WCFServce.svc

when you launch the app and call the wcf service, you will encounter an exception during the service consumption.

it is little difference between the HTTP vs HTTPS binding in DAX WCF service configuration. this is better approach to have two configurations enable in the web.config file. I highlight the difference in bold.

one is the basicHttpBinding for http link

<basicHttpBinding>
        <binding name="reqReplyEndpoint">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
        <binding name="DaxBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:01:00" sendTimeout="00:01:00" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpBinding>


another is basicHttpsBinding for https link

      <basicHttpsBinding>
        <binding name="SecurereqReplyEndpoint">
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
        <binding name="DaxSecureBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:01:00" sendTimeout="00:01:00" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" />
          </security>
        </binding>
      </basicHttpsBinding>


Thursday, April 30, 2015

how to quickly enble impersonated current user to consume the Dynamic AX web service?

My web app is running under the Application Pool assoicated with a specific account, it is perfectly fine to consume the Dynamic AX web serivce.

However, the records were created in the Dynamic AX by the service account after we call the web service to send data to Dynamic AX. if we want to show the record was created the people who run the web application. we can use LogonAsUser property from the CallContext Object. we have to modify the web application by adding following line of code. i highlighted this line of code in Bold

FreeTextInvoiceService2012Http.CallContext context = new FreeTextInvoiceService2012Http.CallContext();
context.LogonAsUser = "YourDomain\\userName";
 textInvoiceService.ClientCredentials.Windows.ClientCredential.UserName = GetAppSettingsValue("UserName"); //which is the serivce account that allow to consume the dax web service
textInvoiceService.ClientCredentials.Windows.ClientCredential.Password = GetAppSettingsValue("Password");


in the Dynamic side,we must configure this service account to be allow impersonation. and grant the user name a role that allow to access the Dynamic AX.

when you check the TextFreeInvoice Tabale in dynamic AX, you should be able to see the user ID instead of the service account ID in the CreatedBy columns

Happy Programming.





Wednesday, February 11, 2015

Configure WCF Service wht HTTPS Binding

One of team mate told me that he was unable to use HTTPS  protocol to access the wcf service that hosts in the DMZ Server. even though he can browse the service with https in the browser.


the issue is caused by the wcf configuration in the web.config file and IIS configuration

the article in the MSDN will provide you the step by step guide to help you walk through the process

How to: Configure an IIS-hosted WCF service with SSL


the only thing i really want to mention is that we do not have to specific the web url in the address attribute when we configure the endpoint in the server web.config.

also we have to set the security mode to be Transport in the Binding configuration.

<services>
      <service name="MySecureWCFService.Service1">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="MySecureWCFService.IService1"/>

        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
 
 <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

Tuesday, March 6, 2012

Submit InfoPath Form Data to Web Service or WCF in InfoPath 2010

when we create a InfoPath form and configure the submit option to allow the user submit the form
to Web service or WCF(windows communication Foundation).






when you construct the data connection by following the data connection wizard, please ensure
you select Entire Form(XML document, Including processing instruction), when you decide to
submit the form to web service and parse the data in the web service.



in the web service you will need to have the following code snippet to parse the xml data and process it and push them back to the Database

 [WebMethod]
        public void SubmitDocument(XmlDocument doc)
        {
            XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
            nsManager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-28T14:26:46");
            nsManager.AddNamespace("dfs", "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution");

            XmlNode root = doc.DocumentElement;
            XmlNode node = root.SelectSingleNode("/dfs:IPDocument/my:myFields", nsManager);
            string recycleItemID = node.SelectSingleNode("/dfs:IPDocument/my:myFields/my:RecycleItemID", nsManager).InnerText;
            string recycleItemName = node.SelectSingleNode("/dfs:IPDocument/my:myFields/my:RecycleItemName", nsManager).InnerText;
            string recycleItemDesc = node.SelectSingleNode("/dfs:IPDocument/my:myFields/my:RecycleItemDescription", nsManager).InnerText;
            string preferredMeasurmentUnitID = node.SelectSingleNode("/dfs:IPDocument/my:myFields/my:PreferredMeasurementUnitID", nsManager).InnerText;

            RecycleItem recycleItemObj = new RecycleItem();
            recycleItemObj.RecycleItemID = recycleItemID;
            recycleItemObj.RecyleItemName = recycleItemName;
            recycleItemObj.RecycleItemDescription = recycleItemDesc;
            recycleItemObj.PreferredMeasureUnitID = Convert.ToInt32(preferredMeasurmentUnitID);

            Update(recycleItemObj);

        }

since we need to have the My namespace for parsing and processing in the code. usually i will use the debug mode to get the My Namespace by the trapping the submit XMLDocument in visual studio 2010. I just figure out we can retrieve the My Namespace value in the InfoPath Designer.

it is very simple and straightforward. select the group field name MyFields, then right click to view the Properties.




click on the Details tab. you will find the Namespace of MyFields. the Namespace is fixed for this group after it is created.