Quantcast
Channel: PTC Community : Unanswered Discussions - Windchill
Viewing all articles
Browse latest Browse all 3592

Writing an Info*Engine-Based Web Service

$
0
0

Hello All,

 

I am hoping somebody can help me. I posted the following question:

 

Info Engine - Standalone Java SOAP Client - Help

 

earlier today and I still cannot get this working.

 

I have now decided to try a different approach and write an Info*Engine-Based Web Service.

 

I am following two sections from the I*E User guide:

  • Writing an Info*Engine-Base Web Service.
  • Username Authentication with Symmetric Keys Example

 

I have succesfully completed the following from the Writing an Info*Engine-Base Web Service section:

 

  • Generate the Truststores and Keystores
    • cd <windchill>/prog_examples/jws
    • ant -f jws-stores.xml
  • Create a Project
    • cd <windchill>
    • mkdir prog_examples/jws/MyProject
    • ant -Dproject.dir=E:\ptc\Windchill_10.2\Windchill\prog_examples\jws\MyProject -Dservlet.name=MathService -Dsecurity.policy=userNameAuthSymmetricKeys -Dservice.type.id=org.myorg.MathService -Dmain.class=org.myorg.MathClient -f bin/adminTools/WebServices/new-project.xml create
  • Write the Info*Engine Tasks for Your Web Service
    • E:\ptc\Windchill_10.2\Windchill\prog_examples\jws\MyProject\src\tasks\org\myorg\MathService\Add.xml
    • E:\ptc\Windchill_10.2\Windchill\prog_examples\jws\MyProject\src\tasks\org\myorg\MathService\Divide.xml
    • E:\ptc\Windchill_10.2\Windchill\prog_examples\jws\MyProject\src\tasks\org\myorg\MathService\Multiply.xml
    • E:\ptc\Windchill_10.2\Windchill\prog_examples\jws\MyProject\src\tasks\org\myorg\MathService\Subtract.xml
  • Deploy Your Web Service
    • cd <windchill>/prog_examples/MyProject/src
    • ant
  • Review Web Service WSDL (I have replaced the Windchill URL with <host>)
    • http://<host>/Windchill/servlet/MathService?wsdl
    • I see a WSDL response that contains all of the functions etc. This looks good! (I think)

 

I have then tried to follow the steps in the Username Authenication with Symmetric Keys Example:

 

  • Import the Server's Public Key into the Client's Certificate Store
    • Transfer server.p12 to client machine
    • Start Certificate Manager using C:\Windows\System32\certmgr.msc
    • import server.p12 into the "Trusted People" store
    • Supply the password. The default password is "changeit"
  • Write the Web Services Client
    • Start Visual Studio, Create New project, Console Application named "WcClient"
    • Right-Click References > Add Service Reference > enter URL to fetch WSDL document
      • This NEVER works first time.
      • I have tried both windchill wcadmin credentials, and LDAP Manager credentials
      • Eventually it will connect and adds the Service
    • Right-Click References > Add Reference > System.Net/System.Security
    • This all looks good! (I think) Visual Studio picks up all of the methods (Add, Divide etc.. from the WSDL)
  • Write the client source code:

 

This is my Program.cs (I have replaced the certificate name with <cert_name>):

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Security.Cryptography.X509Certificates;

 

namespace WcClient

{

    class Program

    {

        static void Main(string[] args)

        {

 

            ExampleService.MathServiceImplClient client = new ExampleService.MathServiceImplClient();

            client.ClientCredentials.UserName.UserName = "???";

            client.ClientCredentials.UserName.Password = "???";

            client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser,StoreName.TrustedPeople, X509FindType.FindBySubjectName, "<cert_name>");

            Console.WriteLine("1+2=" + client.Add(1, 2));

  

        }

    }

}

 

This is my App.config (I have replaced the Windchill URL with <host>):

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <startup>

        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />

    </startup>

    <system.serviceModel>

        <bindings>

            <customBinding>

                <binding name="MathServiceImplPortBinding">

                    <!--The wsdl schema that was used to create this configuration file contained a 'RequireIssuerSerialReference' assertion for a X509Token.  This can not be represented in configuration, you will need to programatically adjust the appropriate X509SecurityTokenParameters.X509KeyIdentifierClauseType to X509KeyIdentifierClauseType.IssuerSerial.  The default of X509KeyIdentifierClauseType.Thumbprint will be used, which may cause interop issues.-->

                    <security defaultAlgorithmSuite="Basic128" authenticationMode="UserNameForCertificate"

                        requireDerivedKeys="false" securityHeaderLayout="Lax" includeTimestamp="true"

                        messageProtectionOrder="SignBeforeEncrypt" messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10"

                        requireSignatureConfirmation="false">

                        <localClientSettings detectReplays="true" />

                        <localServiceSettings detectReplays="true" />

                    </security>

                    <textMessageEncoding messageVersion="Soap11WSAddressing10" />

                    <httpTransport />

                </binding>

            </customBinding>

        </bindings>

      <client>

        <endpoint address="http://<host>:80/Windchill/servlet/MathService"

            binding="customBinding" bindingConfiguration="MathServiceImplPortBinding"

            contract="ExampleService.MathServiceImpl" name="MathServiceImplPort">

          <identity>

            <dns value="<host>" />

          </identity>

        </endpoint>

      </client>

    </system.serviceModel>

</configuration>

 

When I run the program I get the following error:

 

Unhandled Exception: System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="Windchill"'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.

 

So My questions are:

 

  • In Visual Studio When adding the Service reference for the WSDL URL, which credentials should I be using?
  • In Program.cs which username/password should I be using?
  • Why am I getting the (401) Unauthorized error?

 

I have tried wcadmin, cn=Manager, changeit, the username displayed in certmgr.msc, my windows user etc.

 

Any help would be appreciated

 

Thanks


Viewing all articles
Browse latest Browse all 3592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>