Reputation: 983
I tried this code to use a wsse enable SAOP request,but it does not work. Can I get some help?
wsResponseWrapper res = new wsResponseWrapper();
NetworkCredential myCredentials = new NetworkCredential(username, password);
this.srv.Credentials = myCredentials;
this.srv.Timeout = 100000;
res = this.srv.getPlacesList(req);
and here is my app.config
<PullAPSRTC.Properties.Settings>
<setting name="PullAPSRTC_APSRTCService_BookingWSService" serializeAs="String">
<value>http://182.72.148.98:9091/apsrtc-oprs/ws/api/booking</value>
</setting>
</PullAPSRTC.Properties.Settings>
I have worked with SOAP but this is my first time with added security.
Upvotes: 0
Views: 199
Reputation: 983
Here is the declaration and definition of this.srv.
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class BookingWSClient : System.ServiceModel.ClientBase<PullAPSRTC.APSRTCService.BookingWS>, PullAPSRTC.APSRTCService.BookingWS {
public BookingWSClient() {
}
public BookingWSClient(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public BookingWSClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public BookingWSClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public BookingWSClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getConcessionListResponse PullAPSRTC.APSRTCService.BookingWS.getConcessionList(PullAPSRTC.APSRTCService.getConcessionList request) {
return base.Channel.getConcessionList(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getConcessionList(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getConcessionList inValue = new PullAPSRTC.APSRTCService.getConcessionList();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getConcessionListResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getConcessionList(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getBookingDetailsResponse PullAPSRTC.APSRTCService.BookingWS.getBookingDetails(PullAPSRTC.APSRTCService.getBookingDetails request) {
return base.Channel.getBookingDetails(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getBookingDetails(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getBookingDetails inValue = new PullAPSRTC.APSRTCService.getBookingDetails();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getBookingDetailsResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getBookingDetails(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getServiceTypesListResponse PullAPSRTC.APSRTCService.BookingWS.getServiceTypesList(PullAPSRTC.APSRTCService.getServiceTypesList request) {
return base.Channel.getServiceTypesList(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getServiceTypesList(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getServiceTypesList inValue = new PullAPSRTC.APSRTCService.getServiceTypesList();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getServiceTypesListResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getServiceTypesList(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getCancellationInfoResponse PullAPSRTC.APSRTCService.BookingWS.getCancellationInfo(PullAPSRTC.APSRTCService.getCancellationInfo request) {
return base.Channel.getCancellationInfo(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getCancellationInfo(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getCancellationInfo inValue = new PullAPSRTC.APSRTCService.getCancellationInfo();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getCancellationInfoResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getCancellationInfo(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getAvailableBalanceResponse PullAPSRTC.APSRTCService.BookingWS.getAvailableBalance(PullAPSRTC.APSRTCService.getAvailableBalance request) {
return base.Channel.getAvailableBalance(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getAvailableBalance(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getAvailableBalance inValue = new PullAPSRTC.APSRTCService.getAvailableBalance();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getAvailableBalanceResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getAvailableBalance(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getAvailableListByServiceIdResponse PullAPSRTC.APSRTCService.BookingWS.getAvailableListByServiceId(PullAPSRTC.APSRTCService.getAvailableListByServiceId request) {
return base.Channel.getAvailableListByServiceId(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getAvailableListByServiceId(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getAvailableListByServiceId inValue = new PullAPSRTC.APSRTCService.getAvailableListByServiceId();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getAvailableListByServiceIdResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getAvailableListByServiceId(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.registerB2BAgentsDetailsResponse PullAPSRTC.APSRTCService.BookingWS.registerB2BAgentsDetails(PullAPSRTC.APSRTCService.registerB2BAgentsDetails request) {
return base.Channel.registerB2BAgentsDetails(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper registerB2BAgentsDetails(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.registerB2BAgentsDetails inValue = new PullAPSRTC.APSRTCService.registerB2BAgentsDetails();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.registerB2BAgentsDetailsResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).registerB2BAgentsDetails(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getAvailableServiceListResponse PullAPSRTC.APSRTCService.BookingWS.getAvailableServiceList(PullAPSRTC.APSRTCService.getAvailableServiceList request) {
return base.Channel.getAvailableServiceList(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getAvailableServiceList(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getAvailableServiceList inValue = new PullAPSRTC.APSRTCService.getAvailableServiceList();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getAvailableServiceListResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getAvailableServiceList(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.saveBookingDetailsResponse PullAPSRTC.APSRTCService.BookingWS.saveBookingDetails(PullAPSRTC.APSRTCService.saveBookingDetails request) {
return base.Channel.saveBookingDetails(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper saveBookingDetails(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.saveBookingDetails inValue = new PullAPSRTC.APSRTCService.saveBookingDetails();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.saveBookingDetailsResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).saveBookingDetails(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getServiceLayoutNewResponse PullAPSRTC.APSRTCService.BookingWS.getServiceLayoutNew(PullAPSRTC.APSRTCService.getServiceLayoutNew request) {
return base.Channel.getServiceLayoutNew(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getServiceLayoutNew(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getServiceLayoutNew inValue = new PullAPSRTC.APSRTCService.getServiceLayoutNew();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getServiceLayoutNewResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getServiceLayoutNew(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getServiceLayoutResponse PullAPSRTC.APSRTCService.BookingWS.getServiceLayout(PullAPSRTC.APSRTCService.getServiceLayout request) {
return base.Channel.getServiceLayout(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getServiceLayout(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getServiceLayout inValue = new PullAPSRTC.APSRTCService.getServiceLayout();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getServiceLayoutResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getServiceLayout(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getPlacesListResponse PullAPSRTC.APSRTCService.BookingWS.getPlacesList(PullAPSRTC.APSRTCService.getPlacesList request) {
return base.Channel.getPlacesList(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getPlacesList(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getPlacesList inValue = new PullAPSRTC.APSRTCService.getPlacesList();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getPlacesListResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getPlacesList(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getMealDetailsResponse PullAPSRTC.APSRTCService.BookingWS.getMealDetails(PullAPSRTC.APSRTCService.getMealDetails request) {
return base.Channel.getMealDetails(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getMealDetails(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getMealDetails inValue = new PullAPSRTC.APSRTCService.getMealDetails();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getMealDetailsResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getMealDetails(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.getAccommodationDetailsResponse PullAPSRTC.APSRTCService.BookingWS.getAccommodationDetails(PullAPSRTC.APSRTCService.getAccommodationDetails request) {
return base.Channel.getAccommodationDetails(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper getAccommodationDetails(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.getAccommodationDetails inValue = new PullAPSRTC.APSRTCService.getAccommodationDetails();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.getAccommodationDetailsResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).getAccommodationDetails(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.confirmBookingDetailsResponse PullAPSRTC.APSRTCService.BookingWS.confirmBookingDetails(PullAPSRTC.APSRTCService.confirmBookingDetails request) {
return base.Channel.confirmBookingDetails(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper confirmBookingDetails(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.confirmBookingDetails inValue = new PullAPSRTC.APSRTCService.confirmBookingDetails();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.confirmBookingDetailsResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).confirmBookingDetails(inValue);
return retVal.@return;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
PullAPSRTC.APSRTCService.confirmTicketCancellationResponse PullAPSRTC.APSRTCService.BookingWS.confirmTicketCancellation(PullAPSRTC.APSRTCService.confirmTicketCancellation request) {
return base.Channel.confirmTicketCancellation(request);
}
public PullAPSRTC.APSRTCService.wsResponseWrapper confirmTicketCancellation(PullAPSRTC.APSRTCService.wsRequestWrapper arg0) {
PullAPSRTC.APSRTCService.confirmTicketCancellation inValue = new PullAPSRTC.APSRTCService.confirmTicketCancellation();
inValue.arg0 = arg0;
PullAPSRTC.APSRTCService.confirmTicketCancellationResponse retVal = ((PullAPSRTC.APSRTCService.BookingWS)(this)).confirmTicketCancellation(inValue);
return retVal.@return;
}
}
and
BookingWSClient srv = new BookingWSClient();
You can get the complete references from http://182.72.148.98:9091/apsrtc-oprs/ws/api/booking?wsdl
Upvotes: 0
Reputation: 454
Add the header to the request as follows:
string tokennamespace = "o";
DateTime created = DateTime.UtcNow;
string createdStr = created.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
string phrase = Guid.NewGuid().ToString();
var nonce = Convert.ToBase64String(Encoding.UTF8.GetBytes(GetSHA1String(phrase)));
this.srv.Headers.Add(string.Format(
"<{0}:UsernameToken u:Id=\"" + Guid.NewGuid() +
"\" xmlns:u=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" +
"<{0}:Username>" + myCredentials.UserName + "</{0}:Username>" +
"<{0}:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">" +
myCredentials.Password + "</{0}:Password>" +
"<{0}:Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">" +
nonce + "</{0}:Nonce>" +
"<u:Created>" + createdStr + "</u:Created></{0}:UsernameToken>", tokennamespace));
This is the GetSHA1String method code:
public string GetSHA1String(string phrase)
{
SHA1CryptoServiceProvider sha1Hasher = new SHA1CryptoServiceProvider();
byte[] hashedDataBytes = sha1Hasher.ComputeHash(Encoding.UTF8.GetBytes(phrase));
return Convert.ToBase64String(hashedDataBytes);
}
We used this for WCF, here are a couple of references in case you need to customize your request:
http://www.codeproject.com/Articles/19339/WSSE-Authentication-for-WebRequest-Response
http://weblog.west-wind.com/posts/2012/Nov/24/WCF-WSSecurity-and-WSE-Nonce-Authentication
Upvotes: 1