Kopiuj
string endPointAddres = "https://wstest.puesc.gov.pl/seap_wsChannel/DocumentHandlingPort?wsdl";
public void SendToSeap()
{
byte[] byteArray;
try
{
SENT_100 message = new SENT_100
{
Comments = "Komentarz",
DocumentId = "10",
GoodsSender = new Trader
{
TraderAddress = new Address
{
City = "Olsztyn",
Country = "Polska",
Street = "Dworcowa",
HouseNumber = "20",
FlatNumber = "5",
PostalCode = "12-100"
},
TraderInfo = new TraderInfo { IdSisc = "2", TraderIdentityNumber = "8", TraderIdentityType = TraderIdentityType.VATUE, TraderName = "Nazwa 1" }
},
GoodsRecipient = new Trader
{
TraderAddress = new Address
{
City = "Gdańsk",
Country = "Polska",
Street = "Grunwaldzka",
HouseNumber = "50",
FlatNumber = "2",
PostalCode = "20-300"
},
TraderInfo = new TraderInfo { IdSisc = "4", TraderIdentityNumber = "12", TraderIdentityType = TraderIdentityType.NIP, TraderName = "Nazwa 2" }
},
Transport = new TransportSender
{
PlaceOfLoading = new AddressPL
{
City = "Kraków",
Country = CountryPL.PL,
Street = "Limanowskiego",
HouseNumber = "100",
FlatNumber = "9",
PostalCode = "40-500"
},
PlannedStartCarriageDate = new DateTime(2008, 8, 20)
},
GoodsInformation = new GoodsInformationForTrader
{
AmountOfGoods = 1000,
CodeCnClassification = "Code-CN20",
CodePkwiuClassification = "20506",
GoodsName = "Paliwo",
UnitOfMeasure = "litr",
GrossWeightOfGoods = 50,
GrossWeightOfGoodsSpecified = true
},
ResponseAddress = new ResponseAddress
{
EmailChannel = new EmailChannel
{
EmailAddress1 = "localhost1@localhost.pl",
EmailAddress2 = "localhost2@localhost.pl",
EmailAddress3 = "localhost3@localhost.pl"
},
WebServiceChannel = new WebServiceChannel
{
AuthenticationKey = "klucz",
UrlAddress = "http://www.localhost.pl",
Username = "login",
UserPassword = "pass",
WsFromSISC = true
}
},
Statements = new Statements
{
FirstName = "Jan",
LastName = "Kowalski",
Statement1 = true
}
};
XmlSerializer serializer = new XmlSerializer(typeof(SENT_100));
using (MemoryStream ms = new MemoryStream())
{
using (StreamWriter streamWriter = new StreamWriter(ms, Encoding.UTF8))
{
serializer.Serialize(streamWriter, message);
byteArray = ms.ToArray();
XmlMessageString = Encoding.UTF8.GetString(byteArray);
}
}
AcceptDocumentRequest acceptDocumentRequest = new AcceptDocumentRequest();
AcceptDocumentRequest1 acceptDocumentRequest1 = new AcceptDocumentRequest1();
acceptDocumentRequest.document = new documentType();
acceptDocumentRequest.document.content = new contentType();
acceptDocumentRequest.document.content.filename = "komunikat.xml";
acceptDocumentRequest.document.content.mime = mimeType.applicationxml;
acceptDocumentRequest.document.content.Value = byteArray;
acceptDocumentRequest.document.targetSystems = new systemType[] { systemType.SENT };
acceptDocumentRequest1.AcceptDocumentRequest = acceptDocumentRequest;
AcceptDocumentResponse acceptDocumentResponse;
SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.IncludeTimestamp = false;
TextMessageEncodingBindingElement encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement() { AuthenticationScheme = System.Net.AuthenticationSchemes.Digest };
CustomBinding customBinding = new CustomBinding(securityElement, encodingElement, transportElement);
var endpoint = new EndpointAddress(endPointAddres);
DocumentHandlingPortClient client = new DocumentHandlingPortClient(customBinding, endpoint);
client.ClientCredentials.UserName.UserName = userName;
client.ClientCredentials.UserName.Password = pass;
acceptDocumentResponse = client.AcceptDocument(acceptDocumentRequest);
client.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Komunikat musi być w wersji SOAP 1.1. Komunikat SOAP powinien wyglądać następująco:
Pokazuje mi błąd w załączniku zrzut22.jpg. Jeśli użyje w obiekcie klasy CustomBinding obiektu klasy BasicHttpBinding w następujący sposób:
to pokazuje błąd w załączniku zrzut21.jpg i w parametrze InnerException wyjątku jest błąd "The security token could not be authenticated or authorized". Wówczas komunikat SOAP wygląda następujaco:
Którą metodą robić z obiektem klasy CustomBinding bez obiektu klasy BasicHttpBinding czy z tym obiektem ? Jak naprawić błędy związane z tokenem ?