Microsoft .NET

WSE 3.0 Sample of ProvideAndRegisterDocumentSetb

 
private static string FIXED_OBJECT_TYPE_ID                 = "urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1";
private static string FIXED_ASSOCIATION_OBJECT_TYPE        = "urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:Association";
private static string FIXED_ASSOCIATION_TYPE               = "urn:oasis:names:tc:ebxml-regrep:AssociationType:HasMember";
private static string FIXED_PACKAGE_ID                     = "SubmissionSet01";
private static string FIXED_PACKAGE_OBJECT_TYPE            = "urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:RegistryPackage";
private static string FIXED_PACKAGE_CLASSIFICATION_NODE    = "urn:uuid:a54d6aa5-d40d-43f9-88c5-b4633d873bdd";
private static string FIXED_PACKAGE_TYPE_CLASSIFIED_OBJECT = "SubmissionSet";
private static string FIXED_ASSOCIATION_SLOT_NAME          = "SubmissionSetStatus";
private static string FIXED_ASSOCIATION_SLOT_VALUE         = "Original";
private static string RESERVED_RECIPIENT_SLOT              = "urn:refnet:recipient";
private static string RESERVED_SENDING_APPLICATION_SLOT    = "urn:refnet:sending_application";   // optional
private static string RESERVED_ENCAPSULATION_SCHEME_SLOT   = "urn:refnet:encapsulation_scheme";  // optional, default is Enveloped Signed CMS/PKCS#7
 
private void sendMessage()
{
   string userName        = "?????????";
   string userPass        = "?????????";
   string serviceEndpoint = "https://members.staging.referralnet.com.au:9443/services/Referral_Service.Referral_Port_Soap12";
 
   ReferralNet.Referral_ServiceWse proxy = new ReferralNet.Referral_ServiceWse();
   UsernameToken token = new UsernameToken(userName, userPass, PasswordOption.SendPlainText);
   proxy.Url = serviceEndpoint;
   proxy.SetClientCredential<UsernameToken>(token);
   proxy.SetPolicy(new MyPolicy());
 
   // Turn on MTOM/XOP, optionally you can hook this into the payload size, ie: if payload >= 5K then turn it on.
   proxy.RequireMtom = true;
 
   try
   {
      ReferralNet.ProvideAndRegisterDocumentSetRequestType request = new ReferralNet.ProvideAndRegisterDocumentSetRequestType();
      ReferralNet.RegistryRequestType requestType = new ReferralNet.RegistryRequestType();
 
      request.SubmitObjectsRequest = new ReferralNet.SubmitObjectsRequest();
      // Generate a unique id for the request.
      request.SubmitObjectsRequest.id = System.Guid.NewGuid().ToString();
 
      // Create mandatory slot required for recipient and associate it to the request / documentSet.
      // The UID of the recipient should have been taken from the results of a findRecipient call.
      ReferralNet.SlotType1 recipientSlot = createSlot(RESERVED_RECIPIENT_SLOT, new string[] { "urn:?????:?????" });
      // Add in the optional slot to reflect the sending application, the identifier does not have to be known to the ReferralNet service.
      ReferralNet.SlotType1 sendingApplicationSlot = createSlot(RESERVED_SENDING_APPLICATION_SLOT, new string[] { "MySampleApp" });
 
      // Now assign these global slots to the request object
      request.SubmitObjectsRequest.RequestSlotList = new ReferralNet.SlotType1[] { recipientSlot, sendingApplicationSlot };
 
      ArrayList identifiableTypeList = new ArrayList();
      ArrayList documentList = new ArrayList();
 
      // Create the required RegistryPackage object (see this as being a logical folder).
      ReferralNet.RegistryPackageType packageType = new ReferralNet.RegistryPackageType();
      packageType.objectType = FIXED_PACKAGE_OBJECT_TYPE;
      packageType.id = FIXED_PACKAGE_ID;
      packageType.Classification = new ReferralNet.ClassificationType[1];
      packageType.Classification[0] = new ReferralNet.ClassificationType();
      packageType.Classification[0].classifiedObject = FIXED_PACKAGE_ID;
      packageType.Classification[0].classificationNode = FIXED_PACKAGE_CLASSIFICATION_NODE;
 
      // Associate a registered classification the package.
      packageType.Classification[0].nodeRepresentation = "urn:refnet:secure-message";
      // Add the registry package object to the list.
      identifiableTypeList.Add(packageType);
 
      ReferralNet.SlotType1 exampleSlot = createSlot("Version", new string [] { "v4.0"});
      ReferralNet.SlotType1 encapsulationSlot = createSlot(RESERVED_ENCAPSULATION_SCHEME_SLOT, new string[] { "Enveloped Signed CMS/PKCS#7" });
 
      addExtrinsicObjectToPackage("ID_" + System.Guid.NewGuid().ToString(),
                                  "HL7 Referral Document.hl7", // optional
                                  "text/hl7",
                                  true,
                                  null, // optional
                                  System.Text.ASCIIEncoding.UTF8.GetBytes("the data should match the mime type, ie: a well formed HL7 flatwire message"),
                                  new ReferralNet.SlotType1[] { exampleSlot, encapsulationSlot }  // optional,
                                  identifiableTypeList,
                                  documentList);
 
      request.SubmitObjectsRequest.RegistryObjectList = (ReferralNet.IdentifiableType[])identifiableTypeList.ToArray(typeof(ReferralNet.IdentifiableType));
      request.Document = (ReferralNet.ProvideAndRegisterDocumentSetRequestTypeDocument[])documentList.ToArray(typeof(ReferralNet.ProvideAndRegisterDocumentSetRequestTypeDocument));
 
      ReferralNet.RegistryResponseType responseType = null;
      try
      {
         // OK, invoke the ReferralNet Web Service.
         responseType = proxy.ProvideAndRegisterDocumentSetb(request);
      }
      if (responseType != null)
      {
         if (responseType.status.Equals("Success"))
         {
            // fish out the UID from the service, tuck this away, calling RetrieveDocumentSetEvents with this UID will tell you how it is travelling.
            System.Console.WriteLine(responseType.requestId);
         }
         else
         {
            for(int i = 0; i < responseType.RegistryErrorList.RegistryError.Length; i++)
            {
                ReferralNet.RegistryError error = responseType.RegistryErrorList.RegistryError[i];
                ListViewItem item = new ListViewItem();
                item.Text = error.errorCode;
                item.SubItems.Add(error.codeContext);
                item.SubItems.Add(error.severity);
                this.listView2.Items.Add(item);
             }
         }
     }
   }
   catch (SoapException se)
   {
      System.Windows.Forms.MessageBox.Show(se.Code.Name);
   }
   catch (Exception exc)
   {
      System.Windows.Forms.MessageBox.Show(exc.ToString());
   }
}
 
 
private void addExtrinsicObjectToPackage(string id, string name, string mimeType, bool encrypt, string classification, 
                                         byte[] payLoad, ReferralNet.SlotType1[] slots, ArrayList identifiableTypes, ArrayList documents) throws EncryptException;
{
   ReferralNet.ExtrinsicObjectType extrinsicObject = new ReferralNetVIII.ReferralNet.ExtrinsicObjectType();
 
   extrinsicObject.id         = id;
   extrinsicObject.mimeType   = mimeType;
   extrinsicObject.objectType = FIXED_OBJECT_TYPE_ID;
   extrinsicObject.isOpaque   = encrypt;
 
   // Add in optional name attribute if supplied
   if (name != null)
   {
      ReferralNet.InternationalStringType stringType = new ReferralNet.InternationalStringType();
      ReferralNet.LocalizedStringType[] localizedStringType = new ReferralNet.LocalizedStringType[1];
      localizedStringType[0] = new ReferralNetVIII.ReferralNet.LocalizedStringType();
      localizedStringType[0].value = name;
      stringType.LocalizedString = localizedStringType;
      extrinsicObject.Name = stringType;
   }
 
   if (classification != null)
   {
      extrinsicObject.Classification = new ReferralNet.ClassificationType[1];
      extrinsicObject.Classification[0] = new ReferralNet.ClassificationType();
      extrinsicObject.Classification[0].classifiedObject = id;
      extrinsicObject.Classification[0].nodeRepresentation = classification;
   }
 
   // Add in slots if supplied;
   if (slots != null)
   {
      extrinsicObject.Slot = slots;
   }
 
   // Always need to have an Association object accompanying an ExtrinsicObject  
   ReferralNet.AssociationType1 association = new ReferralNet.AssociationType1();
   association.objectType = FIXED_ASSOCIATION_OBJECT_TYPE;
   association.sourceObject = FIXED_PACKAGE_ID;
   association.targetObject = id;
   association.id = "ID_"+System.Guid.NewGuid().ToString();
   association.associationType = FIXED_ASSOCIATION_TYPE;
   association.Slot = new ReferralNetVIII.ReferralNet.SlotType1[] { createSlot(FIXED_ASSOCIATION_SLOT_NAME, new string[] { FIXED_ASSOCIATION_SLOT_VALUE }) };
 
   if(encrypt)
   {
     try{
        // could be Enveloped and Signed CMS/PKCS #7 or XML Digital Signature...whatever the specification dictates.
        payLoad = signAndEncrypt(payLoad);
     }catch (EncryptException exc){
        // do something....
        return;
     }
   }
 
   ReferralNet.ProvideAndRegisterDocumentSetRequestTypeDocument document = new ReferralNet.ProvideAndRegisterDocumentSetRequestTypeDocument();
   document.id = id;
   document.Value = payLoad;
 
   identifiableTypes.Add(extrinsicObject);
   identifiableTypes.Add(association);
   documents.Add(document);
}
 
private ReferralNet.SlotType1 createSlot(string name, string[] values)
{
   ReferralNet.SlotType1 newSlot = new ReferralNet.SlotType1();
   newSlot.name = name;
   newSlot.ValueList = new ReferralNet.ValueListType();
   newSlot.ValueList.Value = values;
   return newSlot;
}

* Sample C# zip

WCF Sample of ProvideAndRegisterDocumentSetb

string userName = "?????????";
string userPass = "?????????";
 
Referralnet.Referral_PortTypeClient client = new Referralnet.Referral_PortTypeClient("Referral_Port_Soap12");
client.ChannelFactory.Endpoint.Behaviors.Remove<System.ServiceModel.Description.ClientCredentials>();
client.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());
client.ClientCredentials.UserName.UserName = userName;
client.ClientCredentials.UserName.Password = userPass;
 
namespace Messaging
{
    class CustomCredentials :ClientCredentials
    {
        public CustomCredentials()
        { }
 
        protected CustomCredentials(CustomCredentials cc)
            : base(cc)
        {
 
        }
 
        public override System.IdentityModel.Selectors.SecurityTokenManager CreateSecurityTokenManager()
        {
            return new CustomSecurityTokenManager(this);
        }
 
        protected override ClientCredentials CloneCore()
        {
            return new CustomCredentials(this);
        }
    }
 
    internal class CustomSecurityTokenManager : System.ServiceModel.ClientCredentialsSecurityTokenManager
    {
        public CustomSecurityTokenManager(CustomCredentials cred)
            : base(cred)
        {
 
        }
 
        public override System.IdentityModel.Selectors.SecurityTokenSerializer CreateSecurityTokenSerializer(System.IdentityModel.Selectors.SecurityTokenVersion version)
        {
            return new CustomTokenSerializer(System.ServiceModel.Security.SecurityVersion.WSSecurity11);
        }
    }
 
    internal class CustomTokenSerializer : WSSecurityTokenSerializer
    {
        public CustomTokenSerializer(SecurityVersion sv)
            : base(sv)
        {
 
        }
 
        protected override void WriteTokenCore(System.Xml.XmlWriter writer, System.IdentityModel.Tokens.SecurityToken token)
        {
            System.IdentityModel.Tokens.UserNameSecurityToken unToken = (System.IdentityModel.Tokens.UserNameSecurityToken)token;
            writer.WriteRaw(
                @"<o:UsernameToken u:Id=""" + token.Id + @""">
                <o:Username>" + unToken.UserName + @"</o:Username>
                <o:Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"">" + unToken.Password + @"</o:Password>
                </o:UsernameToken>");
        }
    }
}

Sample .NET WCF Implementation

 
dev/net.txt · Last modified: 2017/08/16 07:00 (external edit)