1 #region Copyright Notice
2 // ----------------------------------------------------------------------------
3 // Copyright (C) 2003-2005 Microsoft Corporation, All rights reserved.
4 // ----------------------------------------------------------------------------
11 using System
.ServiceModel
;
13 namespace Microsoft
.ServiceModel
.Samples
17 public class UddiClient
19 InquireClient inquireProxy
;
20 PublishClient publishProxy
;
25 inquireProxy
= new InquireClient("Inquire");
26 publishProxy
= new PublishClient("Publish");
29 public void Login(string username
, string password
)
31 get_authToken getToken
= new get_authToken();
32 getToken
.generic
= "2.0";
33 getToken
.userID
= username
;
34 getToken
.cred
= password
;
37 token
= publishProxy
.get_authToken(getToken
);
40 public businessInfo
[] GetBusinessByName(string businessName
)
42 find_business find
= new find_business();
43 find
.name
= new name
[1] { new name() }
;
44 find
.name
[0].Value
= businessName
;
48 businessList bList
= inquireProxy
.find_business(find
);
49 return bList
.businessInfos
;
53 public string PublishBusiness(string businessName
, string description
)
55 save_business newBusiness
= new save_business();
56 newBusiness
.authInfo
= token
.authInfo
;
57 newBusiness
.generic
= "2.0";
58 newBusiness
.businessEntity
= new businessEntity
[1] { new businessEntity() }
;
60 businessEntity myBusinessEntity
= newBusiness
.businessEntity
[0];
61 myBusinessEntity
.name
= new name
[1] { new name() }
;
62 myBusinessEntity
.name
[0].Value
= businessName
;
63 myBusinessEntity
.businessKey
= "";
64 myBusinessEntity
.description
= new description
[1] { new description() }
;
65 myBusinessEntity
.description
[0].Value
= description
;
67 businessDetail myBusinessDetail
= publishProxy
.save_business(newBusiness
);
69 return myBusinessDetail
.businessEntity
[0].businessKey
;
72 public businessInfo
[] GetMyBusinesses()
74 get_registeredInfo getInfo
= new get_registeredInfo();
76 getInfo
.generic
= "2.0";
77 getInfo
.authInfo
= token
.authInfo
;
79 registeredInfo info
= publishProxy
.get_registeredInfo(getInfo
);
80 if (info
== null) return null;
82 return info
.businessInfos
;
85 public businessInfo
GetMyBusinessByName(string businessName
)
87 businessInfo
[] myBusinesses
= this.GetMyBusinesses();
89 foreach (businessInfo bInfo
in myBusinesses
)
91 if (bInfo
.name
[0].Value
== businessName
)
99 public void DeleteMyBusinesses()
101 businessInfo
[] myBusinesses
= this.GetMyBusinesses();
103 delete_business business
= new delete_business();
104 business
.businessKey
= new string[myBusinesses
.Length
];
105 for (int i
= 0; i
< myBusinesses
.Length
; i
++)
107 business
.businessKey
[i
] = myBusinesses
[i
].businessKey
;
109 business
.generic
= "2.0";
110 business
.authInfo
= token
.authInfo
;
112 publishProxy
.delete_business(business
);
115 public void DeleteMyBusiness(string businessKey
)
117 delete_business business
= new delete_business();
118 business
.businessKey
= new string[1] { businessKey }
;
119 business
.generic
= "2.0";
120 business
.authInfo
= token
.authInfo
;
122 publishProxy
.delete_business(business
);
125 public void PrintBusinessInfo(businessInfo bInfo
)
127 if (bInfo
.name
!= null)
129 foreach (name n
in bInfo
.name
)
130 Console
.WriteLine("Name: " + n
.Value
);
133 if (bInfo
.description
!= null)
135 foreach (description desc
in bInfo
.description
)
136 Console
.WriteLine("Description: " + desc
.Value
);
138 Console
.WriteLine("Key: " + bInfo
.businessKey
);
140 if (bInfo
.serviceInfos
!= null)
141 PrintServiceInfos(bInfo
.serviceInfos
);
146 public void PrintServiceInfos(serviceInfo
[] serviceInfos
)
148 Console
.WriteLine("Total Services Offered = " + serviceInfos
.Length
);
149 if (serviceInfos
.Length
> 0)
151 foreach (serviceInfo sInfo
in serviceInfos
)
153 Console
.WriteLine("\tService Key: " + sInfo
.serviceKey
);
155 if (sInfo
.name
!= null)
157 foreach (name n
in sInfo
.name
)
158 Console
.WriteLine("\tName: " + n
.Value
);
169 ((ICommunicationObject
)inquireProxy
).Close();
170 ((ICommunicationObject
)publishProxy
).Close();